I'm trying to create a newsletter function, when a user inputs their name and email into a form, the PHP issues a query to the database to put their answers in the table. I already checked the names of everything and they all seem to be in check, but for some reason "why please no" keeps showing up.
This is my code, it worked once before but I'm not sure what happened.
<?php
mysql_connect("localhost", "root", "root") or die("connecting");
mysql_select_db("ejb")or die("database");
$name = $_POST['name'];
$email = $_POST['email'];
$query = "INSERT INTO 'newsletter'('name', 'email') VALUES ('$name', '$email')";
if(mysql_query($query)) {
echo "updated";
}
else{
echo "why please no";
}
?>
Help would be greatly appreciated!
$query = "INSERT INTO `newsletter`(name, email) VALUES ('".$name."', '".$email."')";
Try using this query, i Think the problem is from 'newsletter'('name', 'email')
instead of newsletter(name, email)
$query = "INSERT INTO your_database.your_table (columnname1, columnname2) VALUES ('$var1','$var2')";
or in your case:
$query = "INSERT INTO ejb.newsletter (name, email) VALUES ('$name','$email')";