Jump to content

php code error


f701234

Recommended Posts

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);

?>

 

Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.