• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

error in code

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.

all help appriciated
0
avo42
Asked:
avo42
  • 4
  • 4
1 Solution
 
snoyes_jwCommented:
String values in queries must be in quotes.

$queryi ="SELECT part_number, quantity_in, part_des FROM parts_db WHERE part_number='M1166'";
0
 
avo42Author Commented:
HI thanks

i found that error also my other error

$p_number = "{$row['part_number']}" ;
should be $p_number =$row['part_number'] ;


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="<? echo $p_number ; ?>"/></th>
             </tr>

but im still unable to echo out the value in the text box am i missing something stupid
$p_number is not avaliating to anything its blank .

thanks in advance
             <tr>
0
 
snoyes_jwCommented:
Inside the while loop, do
print_r($row);
This should show you what values came out of the database.

After the while loop, do
echo "p_number: $p_number";
This should show you what value is assigned to the variable.

If the print_r shows missing data, there's something amiss with the query or the data in the db.
If the echo shows missing data, there's something amiss with the assignment.
If neither shows missing data, there's something amiss with the html form.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
avo42Author Commented:
HI Thanks

They both show missing data


Cheers
0
 
snoyes_jwCommented:
OK.  That means the query returned no results.  Can you run that query using some other method to access the database, such as phpMyAdmin or the mysql CLI or Query Browser or some such?
0
 
avo42Author Commented:
HI Yes

Just deleted all info from my mysql

ive just manualy entered two rows in thera and then there is data visable on my form

how straing

any ideas .

cheers
0
 
snoyes_jwCommented:
I'd guess missing dat then - there weren't any records with that particular part number before, or perhaps there was a space or newline or something before or after.
0
 
avo42Author Commented:
HI

sorted my echoing into the form

all working now as long as i enter data in my db manualy

what i am doing is reading a text file with about 1000 lines using a loop and selection 4 lines from every 11 lines then 4 lines from the next 11 lines and so on until it reaches the end of the file these are then in turn beening updated in my data base with a insert statement within my while loop

the data im my db looks the same as i i had entered it manual

when i do a selct statement from my php to db and call the line i require this code will then not echo out on my form

any ideas for me please.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now