1

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.

2
  • 2
    Do you need to put quotes around $email in your query? You could also switch to using a prepared statement, which takes care of that sort of thing for you. Commented Aug 30, 2013 at 19:53
  • 1
    and quotes around the $today dates as well. 2013-08-31 is going to be interepreted as a 3-term arithmetic subtraction, and end up being 1974. '2013-08-31' (note the quotes) will be treated as a date (or at least a string). Commented Aug 30, 2013 at 19:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.