SQL syntax
Moderator: General Moderators
SQL syntax
can anyone help me to edit it to correct form?
$query="insert into book(buyer) values('".$x."')where id=".$book;
$query="insert into book(buyer) values('".$x."')where id=".$book;
Re: SQL syntax
cty007 wrote:can anyone help me to edit it to correct form?
$query="insert into book(buyer) values('".$x."')where id=".$book;
Code: Select all
$query="insert into book (id_book, buyer) values ("$book","$x") ;Actually (but I'm guessing your intent) you need UPDATE to update an existing row:
(assuming somewhere above you have escaped x and book, and that you're using mysql, and have magic_quotes disabled)
Note which fields are quoted by which quotes.
(assuming somewhere above you have escaped x and book, and that you're using mysql, and have magic_quotes disabled)
Code: Select all
$x = mysql_real_escape_string($x);
$book = mysql_real_escape_string($book);
//...
$query = "UPDATE `book` SET `buyer`='$x' WHERE `id`='$book'";- the_last_tamurai
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 28, 2007 8:24 am
- Location: cairo
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
They are not mandatory. Placing backticks around table (and column) names simply makes it clearer that they are tables. You do need these if you happen to a keyword for a table or column name. For example:
Won't work.
But:
Will work 
Code: Select all
SELECT delete FROM updateBut:
Code: Select all
SELECT `delete` FROM `update`Well, if you've seen it work without, than it must mean they're not mandatory 
It is generally a matter of good coding style, but sometimes they are the only way to go. We've had questions here from people having problems with their queries because they used reserved keywords for column names (I reacall 'desc' in particular). The backtick quotes (`) prevent any such problems, and I strongly suggest them to be used at all times.
It is generally a matter of good coding style, but sometimes they are the only way to go. We've had questions here from people having problems with their queries because they used reserved keywords for column names (I reacall 'desc' in particular). The backtick quotes (`) prevent any such problems, and I strongly suggest them to be used at all times.
- the_last_tamurai
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 28, 2007 8:24 am
- Location: cairo
- Contact:
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA