0

I am new to PHP and SQL, but am creating a login system. The problem I have hit against is:

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 'Surname typed in')' at line 5

So I look into the code, and I believe it refers to:

    mysql_query("INSERT INTO users (email, password, hash, forename, surname) VALUES(
        '". mysql_escape_string($email) ."',
        '". mysql_escape_string($password) ."',
        '". mysql_escape_string($hash) ."',
        '". mysql_escape_string($forename) .",
        '". mysql_escape_string($surname) ."') ") or die(mysql_error());

After looking over, I can't see a syntax error. Anyone spot it?

6
  • 2
    Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. Commented Feb 23, 2013 at 23:43
  • 1
    If you print out the resulting SQL your error will be easy to spot Commented Feb 23, 2013 at 23:43
  • Thanks for the comments, but on reading the PDO info, I have no idea how to select a table. This would make it kind hard for me :) Commented Feb 24, 2013 at 0:07
  • @Splatter You select a table in PDO the same way you select it in mysql_*. Commented Feb 24, 2013 at 0:37
  • mysql_select_db("logintest") ? (sorry, I meant db, not table...2am!) Commented Feb 24, 2013 at 1:44

1 Answer 1

3

On this line:

'". mysql_escape_string($forename) .",
                                  // ^--- no closing single quote here.

You forgot the closing quote mark.

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.