Unable to insert email address to database

by 3 replies
5
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...
#programming #address #database #email #insert #unable
  • 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')";
    • [1] reply
    • Thank you very much, I have solved the problem.
  • 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

Next Topics on Trending Feed

  • 5

    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: