I am adding a new email address to a database.
When I check to see if the user exists using
if (!($stmt = $dbConnection->prepare('SELECT `email_addr` FROM '.TABLE_NAME.' WHERE `email_addr` = ?')))`
everything works OK.
When I attempt to run
if (!($stmt = $dbConnection->prepare('INSERT INTO '.TABLE_NAME.'(`email_addr`,`date_subscribed`,`act_code`,`subscribe_ip`) VALUES (?,?,?,?)' )))
I get the error Unknown column 'email_addr' in 'field list'. I have searched around a lot and thought that maybe adding the backticks would solve the problem, but it did not. If you need more code, please let me know.
SOLVED: The constant had a typo in it. Thank you to everyone for telling me to run the query in PHPmyadmin, that led me to discover the problem.
This error indicates that you are referencing a column name that does not exist. Review your table to ensure that is the proper column name and ensure that you are using the correct variable in your query.
Try removing the ‘`’ from the columns you’re trying to insert into:
In addition, try to echo the query and run it directly in phpMyAdmin to see the result. There may be an issue with your formatting that you are not aware of.