Reputation: 333
Running a MySQL INSERT query, where the only 3 dynamic variables are an e-mail address and 2 date('Y-m-d H:i:s') fields.
I'm getting the 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 'LIST_SUBSCRIBER' at line 1
My Query:
$today = date('Y-m-d H:i:s');
INSERT INTO subscriber_table (
list_subscriber, user_subscriber, robot_subscriber, date_subscriber,
update_subscriber, visibility_subscriber, reception_subscriber,
subscribed_subscriber, included_subscriber
)
VALUES (
'newsletter', $email, 'listserv.valoans.com', $today, $today, 'conceal', 'mail', '1', '0'
)
All SELECT queries work correctly.
Upvotes: 1
Views: 159
Reputation: 782683
It should be:
$sql = "INSERT INTO subscriber_table(list_subscriber, user_subscriber,
robot_subscriber, date_subscriber,
update_subscriber, visibility_subscriber,
reception_subscriber, subscribed_subscriber,
included_subscriber)
VALUES('newsletter', '$email', 'listserv.valoans.com',
'$today', '$today', 'conceal', 'mail',' 1', '0')";
Also, make sure you escape $email
first, with:
$email = mysql_real_escape_string($email);
However, it would be better if you used mysqli or PDO, which support parametrized queries instead of interpolating into strings.
Upvotes: 2