Jump to content

Archived

This topic is now archived and is closed to further replies.

avo

Error in code (While)

Recommended Posts

Hi all

Can 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 there

if 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 returned
but 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

Share this post


Link to post
Share on other sites
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'";

Share this post


Link to post
Share on other sites
[!--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,

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.