I am trying to write a simple INSERT statement to add new users to the database and it is not working, meaning, none of the data I am trying to insert to the table gets inserted. I have been trying to troubleshoot this issue for hours now, with no success. My attempts to write the insert statements are below, and they look correct to me, so it is hard for me to troubleshoot. All columns in the insert statements exist in my table and are in that exact order. I would appreciate it if someone could advice what might be the problem.
My Connection
//Create mysql connect variable
$conn = mysql_connect('1122334455.host.com', 'john', 'password');
//kill connection if error occurs
if(!$conn){
die('Error: Unable to connect.' . '<br>' . mysql_error());
}
//connect to mysql database
mysql_select_db("jefffffff89", $conn);
The INSERT statements that I have tried so far:
Attempt 1:
mysql_query("INSERT INTO users (id, email, company-name, city, state, phone, password, first, last)
VALUES('','hello@gmail.com','johnnys inc','main','NY','443-333-3444','1234567','matt','williams')",$conn);
Attempt 2:
$query = "INSERT INTO users (id, email, company-name, city, state, phone, password, first, last)
VALUES('','hello@gmail.com','johnnys inc','main','NY','443-333-3444','1234567','matt','williams')";
mysql_query($query,$conn);
I was able to easily add a record to the following table as follows and it works just fine (so, I followed the same logic to insert above, but it does not successfully insert):
mysql_query("INSERT INTO log (log_id, txn_id, email) VALUES('','hello','world')", $conn);
One of your column names contains a hyphen:
Assuming that’s intentional, you need to escape it with backticks:
However it would be better to change your column to have a name that doesn’t contain a hyphen.