Page 1 of 1

insert and select, not select into

Posted: Sat Jun 05, 2004 9:50 pm
by Illusionist
here is my current sql:

Code: Select all

"INSERT INTO user_items VALUES('{$_SESSIONї'id']}', '(SELECT itemID FROM item WHERE itemName=$name)')"
Its inside a function that takes $name as a parameter. But for some reason, the SELECT keeps returning 0.
I'm pretty sure that means what im doing is wrong, so waht is the correct way?

Posted: Sat Jun 05, 2004 10:04 pm
by markl999
What's the full code look like?
Are you doing stuff like the following to debug?

Code: Select all

$sql = "INSERT INTO user_items VALUES('{$_SESSION['id']}', '(SELECT itemID FROM item WHERE itemName=$name)')";
echo $sql;
mysql_query($sql) or die(mysql_error());

Posted: Sat Jun 05, 2004 10:15 pm
by Illusionist
already tried it keep getting:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT itemID FROM item WHERE itemName='Pillow'))

Posted: Sat Jun 05, 2004 10:18 pm
by Illusionist

Code: Select all

INSERT INTO user_items (userID,itemID) VALUES('24', (SELECT itemID FROM item WHERE itemName='Pillow'))

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT itemID FROM item WHERE itemName='Pillow'))'

Posted: Sat Jun 05, 2004 10:19 pm
by markl999
What version of mysql?

Posted: Sat Jun 05, 2004 10:23 pm
by Illusionist
4.0.20

Posted: Sat Jun 05, 2004 10:24 pm
by markl999
You need 4.1 or above for subselects.

Posted: Sat Jun 05, 2004 10:25 pm
by Illusionist
dangit. Ok, so ill have to do 2 seperate queries? that sucks! lol