avo Posted June 6, 2006 Share Posted June 6, 2006 Hi allCan any please tell me if there is and error in this code it looks ok to me but doing straing things[code]if ($_POST['sel_search']) {mysql_connect($dbhost, $dbuser, $dbpass)or die (mysql_error ());mysql_select_db ($dbname) or die ( mysql_error ());$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number=M1166";$resulti = mysql_query ($queryi) or die ( mysql_error () );while ($row = mysql_fetch_assoc($resulti)){$p_number = "{$row['part_number']}";$q_in_stock = "{$row['quantity_in']}";$p_description = "{$row['part_des']}";$o_re_o_quantity = "{$row['reorder_quantity']}";$l_location = "{$row['location']}";$u_on = "{$row['used_on']}";$c_code = "{$row['code']}";$s_size = "{$row['size']}";}}[/code]the error is Unknown column 'M1166' in 'where clause'but im not looking for a column thereif i change a line to this .[code]$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db";[/code]i would expect nothing to be returnedbut it selects a line from my database and allways the same one.ive tryed just running the code on its own incase there was something been added but still the same .all help appriciated Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/ Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 Put single quotes around the part number.$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='M1166'";or$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='$myvar'"; Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/#findComment-42527 Share on other sites More sharing options...
avo Posted June 6, 2006 Author Share Posted June 6, 2006 [!--quoteo(post=380718:date=Jun 6 2006, 07:30 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 07:30 PM) [snapback]380718[/snapback][/div][div class=\'quotemain\'][!--quotec--]Put single quotes around the part number.$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='M1166'";or$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='$myvar'";[/quote]Hi thanks i tryed assigning a variable and single quotes just tryed it again and when i echo the query it is now correct but still unable to echo the array into the text box[code]<?include ('includes/dbconfig.php'); $myvar='M1166'; $db=mysql_connect($dbhost, $dbuser, $dbpass)or die (mysql_error ());mysql_select_db ($dbname) or die ( mysql_error ());$query ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='$myvar'"; $result = mysql_query ($query,$db) or die ( mysql_error () );while ($row = mysql_fetch_array($result)){$p_number = "{$row['part_number']}";} ?> </th> </tr> <tr> <th height="276" colspan="2" scope="col"> <table width="400" border="0" align="center" cellpadding="0" cellspacing="2"> <tr> <th width="192" align="left" valign="middle" class="style7" scope="col">Part Number </th> <th width="208" align="center" valign="middle" scope="col"><input type="text" name="p_number" value="<? echo $p_number ?>"/></th> </tr> <tr> </table> <?[/code]thanks again, Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/#findComment-42534 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 Change this:$p_number = "{$row['part_number']}";to this:$p_number = $row['part_number'];And if you're going to use short tags, use them like this:<th width="208" align="center" valign="middle" scope="col"><input type="text" name="p_number" value="<?=$p_number?>"/></th> Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/#findComment-42535 Share on other sites More sharing options...
avo Posted June 6, 2006 Author Share Posted June 6, 2006 [!--quoteo(post=380726:date=Jun 6 2006, 07:58 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 07:58 PM) [snapback]380726[/snapback][/div][div class=\'quotemain\'][!--quotec--]Change this:$p_number = "{$row['part_number']}";to this:$p_number = $row['part_number'];And if you're going to use short tags, use them like this:<th width="208" align="center" valign="middle" scope="col"><input type="text" name="p_number" value="<?=$p_number?>"/></th>[/quote]Hi Thanks but for some reson still unable to echo out result into text box[code]mysql_connect($dbhost, $dbuser, $dbpass)or die (mysql_error ());mysql_select_db ($dbname) or die ( mysql_error ());$query ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number ='M1166'"; $result = mysql_query ($query) or die ( mysql_error () );while ($row = mysql_fetch_assoc($result)){$p_number = $row['part_number'];} ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="2"> <tr> <th width="192" align="left" valign="middle" class="style7" scope="col">Part Number </th> <th width="208" align="center" valign="middle" scope="col"><input type="text" name="textfield" value="<?=$p_number?>"/></th> </tr> <tr>[/code]Any ideas why please (this should be easy am i missing something realy stupid?thanks Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/#findComment-42545 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 Did you try echoing "$row['part_number']" to make sure something is actually in there?Also, try using mysql_fetch_array instead of mysql_fetch_assoc(). Quote Link to comment https://forums.phpfreaks.com/topic/11348-error-in-code-while/#findComment-42548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.