Jump to content


Photo

Error in code (While)


  • Please log in to reply
5 replies to this topic

#1 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 06 June 2006 - 06:22 PM

Hi all

Can any please tell me if there is and error in this code it looks ok to me but doing straing things
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']}";
}}
the error is Unknown column 'M1166' in 'where clause'
but im not looking for a column there

if i change a line to this .
$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db";
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
Im loving it ........

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:30 PM

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'";


Info: PHP Manual


#3 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 06 June 2006 - 06:56 PM

[!--quoteo(post=380718:date=Jun 6 2006, 07:30 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 07:30 PM) View Post[/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


<?
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>
          <?
thanks again,

Im loving it ........

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 06:58 PM

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>

Info: PHP Manual


#5 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 06 June 2006 - 07:14 PM

[!--quoteo(post=380726:date=Jun 6 2006, 07:58 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 07:58 PM) View Post[/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
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>

Any ideas why please (this should be easy am i missing something realy stupid?

thanks
Im loving it ........

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 07:16 PM

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().

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users