Jump to content

Form not entering data into the database


dazz_club

Recommended Posts

Hi all,

 

I have an order form, order.php that inserts the users detail collected into a database.

 

I have put an echo to display wether it has failed or it successfully inserted the details into the database.

 

when i test it out and then submit the form it displays a successfull message. Sadly when i go to see it in the database, its not there.

 

any help would be great

 

heres my code for order.php

<?php 
session_start();
require_once("includes/connection.php"); 

if(isset($_POST['submit']))
{
$company_name=$_POST['company_name'];
$company_email=$_POST['company_email'];
$company_telephone_number=$_POST['company_telephone_number'];
$address=$_POST['address'];
$address_1=$_POST['address_1'];
$address_2=$_POST['address_2'];
$address_3=$_POST['address_3'];
$town=$_POST['town'];
$city=$_POST['city'];
$post_code=$_POST['post_code'];
$free_sample_of_room_thermometers=$_POST['free_sample_of_room_thermometers'];



$errors .= (empty($post_code)) ? "<span class=\"emptyFields\">We reuqire your postcode.</span>" : "";
$errors .= (empty($company_name)) ? "<span class=\"emptyFields\">We require a company name.</span>" : "";
$errors .= (empty($company_telephone_number)) ? "<span class=\"emptyFields\">We need your telepone number to contact you.</span>" : "";
$errors .= (empty($company_email)) ? "<span class=\"emptyFields\">To help you, we require your email.</span>" : "";


//need to add country, product and state
if (!$errors)
{
if(!get_magic_quotes_gpc())
{
$company_name = addslashes($company_name);
$company_email = addslashes($company_email);
$company_telephone_number= addslashes($company_telephone_number);
$address= addslashes($address);
$address_1= addslashes($address_1);
$address_2= addslashes($address_2);
$address_3= addslashes($address_3);
$town= addslashes($town);
$city= addslashes($city);
$post_code= addslashes($post_code);
$free_sample_of_room_thermometers= addslashes($free_sample_of_room_thermometers);

}
@ $db = new mysqli('localhost', 'root', 'xx', 'xx');

if (mysqli_connect_errno())
{
echo 'error';
}

$query = " INSERT INTO order_enquiries (company_name, company_email, company_telephone_number, address, address_1, address_2, address_3, town, city, post_code, free_sample_of_room_thermometers  ) VALUES ('".$company_name."', '".$company_email."', '".$company_telephone_number."', '".$telephone."', '".$address."', '".$address_1."', '".$address_2."', '".$address_3."', '".$town."', '".$city."', '".$post_code."', '".$free_sample_of_room_thermometers."')";
$result = $db->query($query);

$success .= "<span class=\"emptyFields\">Thank you, your enquiry has been sent.</span>";


//need to add country, product and state
if ($success);

}
}		
?>
<?php echo ($errors) ? "<p class=\"errorSentence\">Some fields have not been completed: $errors</p>" : ""; ?>
<?php echo ($success); ?>

 

kind regards

Dazzclub

Link to comment
https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/
Share on other sites

I only checked quickly, but there is a problem with your query for the insert.  I might be going mad, or maybe my eyes are tired, but check it out:

 

You have 11 values you are trying to fill in the database, but you have 12 variables. :) you should either take a variable off, or add a field into the first bit.  hope that sorts it for you. :)

 

Goose.

 

EDIT: I felt bad just posting what I thought the problem was without actually finding it.  The variable $telephone is in the values, but you havent put a field for it, the variable isn't defined earlier on either.

 

Enjoy :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.