mysql_query ("
INSERT INTO items
(index, name, description, given_by,
cost_to_tcs, starting_bid, auction_type)
VALUES
('{$index_number}','{$name}','{$description}','{$donated_by}',
NULL,'{$auction_type}','{$starting_bid}')
")
or die("3: " . mysql_error());
Errors with:
3: 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 ''index', 'name', 'description', 'given_by', 'cost_to_tcs', 'starting_bid', 'auct' at line 1
Thanks for any help.
index is mysql Reserved keyword, wrap index with (back tick) `` `
INSERT INTO items
(`index`, `name`, `description`, `given_by`,
`cost_to_tcs`, `starting_bid`, `auction_type`)
Reserve key words
try like that:
mysql_query ("
INSERT INTO items (
`index`,
`name`,
`description`,
`given_by`,
`cost_to_tcs`,
`starting_bid`,
`auction_type`)
VALUES(
'$index_number',
'$name',
'$description',
'$donated_by',
NULL,
'$auction_type',
'$starting_bid')
")
or die("3: " . mysql_error());
also make sure to safe the data with mysql_real_escape_string();
Related
$bzSendMail = mysqli_query($Connection, "INSERT INTO messages_inbox (from, towho, subject, text, rcvdat) VALUES ('$MyID', '$SenderID', '$subject', '$text' ,'$sentat')");
I'm trying to make this query works, but it keeps showing me the following error!
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 'from, towho, subject, text, rcvdat) VALUES ('1', '2', 'd', 'd' ,'2014-09-07 17:0' at line 1
Anyone can help me?
you are using
FROM
as a column name in your table. You can use '' to specify the column name but it is always better not to use that kind of names as your column names.
$bzSendMail = mysqli_query($Connection, "INSERT INTO messages_inbox (`from`, `towho`, `subject`, `text`, `rcvdat`) VALUES ('$MyID', '$SenderID', '$subject', '$text' ,'$sentat')");
From is a key word in Mysql use backward quotes to skip this as follows
$bzSendMail = mysqli_query($Connection, "INSERT INTO messages_inbox (`from`, `towho`, `subject`, `text`, `rcvdat`) VALUES ('$MyID', '$SenderID', '$subject', '$text' ,'$sentat')");
from is a reserved word in sql. Make backticks around it.
I cant enter now() to MySQL column which has datetime stamp option:
$sth = mysql_query("INSERT INTO data (id, user_id,data,datetime,desc) ".
"VALUES ('', '$userid','$data',now(),'$desc')",$link)
or die("Query failed ");
MySQL:
4 datetime timestamp No CURRENT_TIMESTAMP
Output:
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
'desc) VALUES ('', '','',NOW(),'')'
at line 1
Remove quotes for now() as it is a MYSQL function. Also it is not now(), it is NOW().
$sth = mysql_query("INSERT INTO data (id, user_id,data,datetime,desc) VALUES ('', '$userid','$data',NOW()),'$desc'",$link) or die("Query failed ");
I guess the problem is because desc and datetime are a reserved words, and if id is AUTOINCREMENT you can remove from values. Try this:
$sth = mysql_query("INSERT INTO data (user_id, `data`,`datetime`,`desc`) ".
"VALUES ('$userid','$data',NOW(),'$desc')",$link)
or die(mysql_error());
And remember that mysql extension is deprecated, check mysqli or PDO.
Edited: Added some error detection
I'm a newbie and I've been trying for over an hour to solve this simple query:
mysql_query("INSERT INTO `tracks` (artistID, albumID, format, trackID, niceTitle, title, trackNumber, description, pictureURL, playCount) VALUES('$artistID', '$albumID[$i]', 'hq','$ID[0]', '$trackName', '$title', '$j', '$description', '$pictureURL', '$playCount'") or die(mysql_error());
I just get this error every time:
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 '' at line 1
I've done mysql_escape_string() on all variables too. Any ideas?
You are missing the final closing ):
mysql_query("INSERT INTO `tracks` (artistID, albumID, format, trackID, niceTitle, title, trackNumber, description, pictureURL, playCount) VALUES('$artistID', '$albumID[$i]', 'hq','$ID[0]', '$trackName', '$title', '$j', '$description', '$pictureURL', '$playCount')") or die(mysql_error());
You have no ending parenthesis ")" in your query
$to = '555';
$from = '555';
$message = 'stuff';
mysql_query("INSERT INTO `convo` (to, from, content)
VALUES ( '$to', '$from', '$message' )") or die(mysql_error());
I can't figure out what is wrong with my above simple query. What obvious thing am I missing?
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 'to, from, content) VALUES ( '555', '555', 'stuff' )' at line 1
It looks like to is a MySQL reserved word.
Try
mysql_query("INSERT INTO `convo` (`to`, `from`, `content`) VALUES ( '$to', '$from', '$message' )") or die(mysql_error());
TO is a MySQL keyword. To fix this, wrap backticks around your to field.
I am using php and trying to add a item to my MySQL database.
If I use the following code it works:
mysql_query("INSERT INTO `intranet`.`product_form` (`id`, `ProductName`, `ProductInitiatedBy`) VALUES (NULL, 'item1', 'item2')") or die("Could not perform select query - " . mysql_error());;
However, if I use the following code it doesn't work:
$product_name=("tom");
mysql_query("INSERT INTO `intranet`.`product_form` (`id`, `ProductName`, `ProductInitiatedBy`) VALUES (NULL, $product_name, 'item2')") or die("Could not perform select query - " . mysql_error());;
I get an error that says:
Could not perform select query - Unknown column 'ProductName1234' in
'field list'
The ProductName1234 is the data from $product_name and should be the data I am trying to add and not the column.
When you insert strings like that, you need to surround them in quotes, else MySQL will think you are trying to specify a column from somewhere to insert data from.
mysql_query("INSERT INTO intranet.product_form (id, ProductName, ProductInitiatedBy) VALUES (NULL, \"$product_name\", 'item2')");
Change:
mysql_query("INSERT INTO `intranet`.`product_form` (`id`, `ProductName`, `ProductInitiatedBy`) VALUES (NULL, $product_name, 'item2')") or die("Could not perform select query - " . mysql_error());;
to:
mysql_query("INSERT INTO `intranet`.`product_form` (`id`, `ProductName`, `ProductInitiatedBy`) VALUES (NULL, '$product_name', 'item2')") or die("Could not perform select query - " . mysql_error());
You need to add ' to $product_name:
VALUES (NULL, '$product_name', 'item2')
^ ^