DustyJoe
01-07-2012, 10:48 PM
I'm having trouble with spaces within mysql table contents.
Everything pulls from the database fine, spaces and all... when I pull using an integer associated with that particular row, now when I try and pull from the database based upon a string with a space, it does not seem to pull the entire sting. Just the data before the space.
For instance, when I try to select and pull "AMC - Gremlin"..
I get Unknown column 'AMC' in 'where clause'
Here is the start:
$query = "SELECT * FROM BAMFG_vehicle";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$output .= "<tr>
<td width=100><img src='blank_img.gif'</td>
<td><a href='bamfg_vehicle.php?do=view_vehicle&id=".$row['vehicle_id']."'>".$row['year']." - ".$row['make_model']."</a></td>
<td width=50>".$row['view_cnt']."</a></td>
</tr>";
$output2 .= "<OPTION VALUE=".$row['make_model'].">".$row['make_model']."";
}
Here is the code within the template:
<form action="bamfg_vehicle.php?do=search_vehicle" method="post" enctype="multipart/form-data">
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
<table width="500" border="1" align="center">
<tr><td width="80">
<SELECT SIZE="6" NAME="year">
<OPTION VALUE="2010"> 2013
<OPTION VALUE="2010"> 2012
<OPTION VALUE="2010"> 2011
<OPTION VALUE="2009"> 2009
<OPTION VALUE="2008"> 2008
<OPTION VALUE="2007"> 2007
<OPTION VALUE="2006"> 2006
<OPTION VALUE="2005"> 2005
<OPTION VALUE="2004"> 2004
<OPTION VALUE="2003"> 2003
</SELECT>
</td>
<td align="left">
<SELECT SIZE ="6" NAME="make_model">
{vb:raw output2}
</SELECT>
<br>
</td>
</tr>
<tr><td colspan="2" align="right">
<input type="submit" />
</form>
</td></tr>
</table>
Here is my query code:
if($_REQUEST['do'] == 'search_vehicle') {
$year = $_POST['year'];
$make_model = $_POST['make_model'];
$query = "SELECT * FROM BAMFG_vehicle WHERE make_model = $make_model";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$vehicle_id = $row['vehicle_id'];
$year = $row['year'];
$make_model = $row['make_model'];
}
// *** SEND VARIABLES TO TEMPLATE
$templater = vB_Template::create('BAMFG_vehicle_view');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('vehicle_id', $vehicle_id);
$templater->register('year', $year);
$templater->register('make_model', $make_model);
print_output($templater->render());
}
Everything pulls from the database fine, spaces and all... when I pull using an integer associated with that particular row, now when I try and pull from the database based upon a string with a space, it does not seem to pull the entire sting. Just the data before the space.
For instance, when I try to select and pull "AMC - Gremlin"..
I get Unknown column 'AMC' in 'where clause'
Here is the start:
$query = "SELECT * FROM BAMFG_vehicle";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$output .= "<tr>
<td width=100><img src='blank_img.gif'</td>
<td><a href='bamfg_vehicle.php?do=view_vehicle&id=".$row['vehicle_id']."'>".$row['year']." - ".$row['make_model']."</a></td>
<td width=50>".$row['view_cnt']."</a></td>
</tr>";
$output2 .= "<OPTION VALUE=".$row['make_model'].">".$row['make_model']."";
}
Here is the code within the template:
<form action="bamfg_vehicle.php?do=search_vehicle" method="post" enctype="multipart/form-data">
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
<table width="500" border="1" align="center">
<tr><td width="80">
<SELECT SIZE="6" NAME="year">
<OPTION VALUE="2010"> 2013
<OPTION VALUE="2010"> 2012
<OPTION VALUE="2010"> 2011
<OPTION VALUE="2009"> 2009
<OPTION VALUE="2008"> 2008
<OPTION VALUE="2007"> 2007
<OPTION VALUE="2006"> 2006
<OPTION VALUE="2005"> 2005
<OPTION VALUE="2004"> 2004
<OPTION VALUE="2003"> 2003
</SELECT>
</td>
<td align="left">
<SELECT SIZE ="6" NAME="make_model">
{vb:raw output2}
</SELECT>
<br>
</td>
</tr>
<tr><td colspan="2" align="right">
<input type="submit" />
</form>
</td></tr>
</table>
Here is my query code:
if($_REQUEST['do'] == 'search_vehicle') {
$year = $_POST['year'];
$make_model = $_POST['make_model'];
$query = "SELECT * FROM BAMFG_vehicle WHERE make_model = $make_model";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$vehicle_id = $row['vehicle_id'];
$year = $row['year'];
$make_model = $row['make_model'];
}
// *** SEND VARIABLES TO TEMPLATE
$templater = vB_Template::create('BAMFG_vehicle_view');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('vehicle_id', $vehicle_id);
$templater->register('year', $year);
$templater->register('make_model', $make_model);
print_output($templater->render());
}