Character Mismatch?

when I select a value on the previous page that is all numeric the page displays fine with the code below, but when I pick something like “testing” or “H70001” I get an error: Unknown column ‘H70001’ in ‘where clause’

The database table should be varchar and H70001 and “testing” are both stored in the table. Any clues what I’m doing wrong?


search.php <?php $con = mysql_connect("*","*","*"); $search_results=$_POST['ddtest']; $database="tms"; if (!$con) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tbl_Entry where serial_number=$search_results"; $result=mysql_query($query) or die(mysql_error()); $num=mysql_numrows($result); mysql_close(); ?> Insert New Records

<?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"ID"); $f2=mysql_result($result,$i,"serial_number"); $f3=mysql_result($result,$i,"desc"); $f4=mysql_result($result,$i,"dmg"); $f5=mysql_result($result,$i,"dmg_desc"); $f6=mysql_result($result,$i,"pic_link"); $f7=mysql_result($result,$i,"creation_date"); $f8=mysql_result($result,$i,"created_by"); $f9=mysql_result($result,$i,"last_update_date"); $f10=mysql_result($result,$i,"last_update_by"); ?> <?php $i++; } ?>
ID Serial Number Description Damage? Damage Desc pic_link creation_date created_by last_update_date last_update_by
<?php echo $f1; ?> <?php echo $f2; ?> <?php echo $f3; ?> <?php echo $f4; ?> <?php echo $f5; ?> <?php echo $f6; ?> <?php echo $f7; ?> <?php echo $f8; ?> <?php echo $f9; ?> <?php echo $f10; ?>

<?php $i=0; while ($i < $num) { $ff2=mysql_result($result,$i,"serial_number"); ?> <?php echo $ff2; ?> <?php $i++; } ?> [/php]

Try this for your sql statement:

$clean_search_results = addslashes(trim($search_results));

$query=“SELECT * FROM tbl_Entry where serial_number=’$clean_search_results’”;

Sponsor our Newsletter | Privacy Policy | Terms of Service