Unable to insert email address to database

by Ebbam
3 replies
Hi everybody there! Pls I want someone to bail me out, I am trying to insert email address to my datbase from my webpage but I am getting this syntax error: syntax error, check manual that correspond to your mysql version for the right syntax to us near '@yahoo.com at line 1.

the code is:
$sql = "INSERT INTO subscribers(`id`,`first`,`last`,`email`) VALUES('','".$first."','".$last."','".$email."')";
etc...
#address #database #email #insert #unable
  • Profile picture of the author Ken Durham
    If your ID field is auto-increment, you do not need to include it in your query.
    If you are using double quotes for the query string then you do not need to concatenate the string and variables. So it would be something like this.

    $sql = "INSERT INTO subscribers (`first`,`last`,`email`) VALUES('$first','$last','$email')";
    Signature

    yes, I am....

    {{ DiscussionBoard.errors[4576788].message }}
    • Profile picture of the author Ebbam
      Thank you very much, I have solved the problem.
      {{ DiscussionBoard.errors[4588181].message }}
  • Profile picture of the author lordspace
    Hey,

    by using the code above you'll get hacked soon or later.

    make sure you escape your variables.
    PHP: mysql_real_escape_string - Manual

    Don't believe me ?
    Search for SQL injections
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[4696049].message }}

Trending Topics