f701234 Posted May 1, 2022 Share Posted May 1, 2022 Hi I am having an error in my code. What im trying to do is make a contact form where users input their information (Firstname, Lastname, PhoneNo, Email, and Message) then it gets sent to my database on phpmyadmin (called contactform) and their information should then show up on the table (contact-data) showing name, id, email address, the message etc. However the error im getting is this Fatal error: Uncaught mysqli_sql_exception: Unknown column 'message' in 'field list' in C:\xampp\htdocs\form\form-process.php:6 Stack trace: #0 C:\xampp\htdocs\form\form-process.php(6): mysqli->query('INSERT INTO `co...') #1 {main} thrown in C:\xampp\htdocs\form\form-process.php on line 6 and here is my code from the process.php and the config.php (which is supposed to connect to the database) Process - <?php include("config.php"); extract($_POST); $sql = "INSERT INTO `contact-data`(`firstname`, `lastname`, `phone`, `email`, `message`) VALUES ('".$firstname."','".$lastname."',".$phone.",'".$email."','".$message."')"; $result = $mysqli->query($sql); if(!$result){ echo "Couldn't enter data".$mysqli->error; } echo "Thank You For Contacting Us "; $mysqli->close(); ?> Confrig- <?php define("DB_HOST","localhost"); define("DB_USER","root"); define("DB_PASSWORD",""); define("DB_NAME","contactform"); $mysqli = new mysqli(DB_HOST,DB_USER, DB_PASSWORD,DB_NAME); ?> Quote Link to comment https://forums.phpfreaks.com/topic/314751-php-code-error/ Share on other sites More sharing options...
Barand Posted May 1, 2022 Share Posted May 1, 2022 (edited) That message is telling you there is not a column called "message" in the contact_data table. Check your database - could be a spelling mistake in your table definition. BTW, dont use "-" in SQL identifiers (table and column names) but use "_" instead. Hyphens can be interpreted as minus signs in queries. For example SELECT first-name FROM user will be interpreted as column first minus column name. Edited May 1, 2022 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/314751-php-code-error/#findComment-1595863 Share on other sites More sharing options...
f701234 Posted May 1, 2022 Author Share Posted May 1, 2022 wow that was so easy, thanks a lot for the help Quote Link to comment https://forums.phpfreaks.com/topic/314751-php-code-error/#findComment-1595864 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.