Web Hosting Talk







View Full Version : Can someone help me with Mysql - Its simple


saghir69
03-28-2008, 04:22 PM
Hi

I'm sure it will be simple for someone who is good with php.


// i'm adding some data to my db - this works
mysql_query("INSERT INTO table (orderid, otherfield)
VALUES ('" . $orderid . "','" . $otherfield. "') ") or die(mysql_error());
// to continue with my script I need the row "id" of the row I just entered above. "id" is a field in my db set to auto_increment
// is there a easy way to get that

// this is how i'm trying but i'm geting a odd error
$result = mysql_query("select id from table Where orderid = $orderid", $link)
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];

when i run this script i get this error

Could not read data because Unknown column '676777d676' in 'where clause'

'676777d676' is the value of $orderid

can someone spot what i'm doing wrong?

stdunbar
03-28-2008, 04:40 PM
Put the parameter into the where clause the same way you did it with the insert - wrap it with quotes.

etogre
03-28-2008, 05:03 PM
$result = mysql_query("SELECT id FROM table WHERE orderid = '" . $orderid . "'");

beaten