Jump to content

Adding data into MySQL table


f.ismayil

Recommended Posts

I have MySQL table with the following fields:

 

user=>varchar

product=>varchar

Amount=>int

Date=>date

Note=>tinytext

 

I can't add value to these field by the following php code:

 

$date = date("Y.m.d");

$query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')";

$result = mysql_query($query) or die(mysql_error());

 

I receive the following warning:

 

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 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 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1

Link to comment
Share on other sites

The following code is also not working:

 

$query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '2011-04-10', 'hello')";

$result = mysql_query($query) or die(mysql_error());

 

Gives the following message:

 

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 'order VALUES ('farhad', 'Mango', '10', '2011-04-10', 'hello')' at line 1

Link to comment
Share on other sites

order, the part of the query that is being pointed out in the error messages, is a reserved mysql keyword. You either need to enclose it in back-ticks `order` every time you use it as your table name or you need to rename your table to something else.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.