mysql insert error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

mysql insert error

Post by pinehead18 »

Code: Select all

mysql_query("INSERT INTO newsletter (first_name, last_name, email, birthday) VALUES ($first_name, $last_name, $email, $birthday)") or die(mysql_error());
thats my code.

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

thats my error


Any idea?

Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mysql insert error

Post by Christopher »

Quote your strings, and remember to escape the values before building the SQL (mysql_real_escape_string()):

Code: Select all

mysql_query("INSERT INTO newsletter (first_name, last_name, email, birthday) VALUES ('$first_name', '$last_name', '$email', '$birthday')") or die(mysql_error());
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

What aborint said, or one of these values isn't set. "$first_name, $last_name, $email, $birthday"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply