dazz_club Posted March 31, 2008 Share Posted March 31, 2008 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 More sharing options...
eddierosenthal Posted March 31, 2008 Share Posted March 31, 2008 please echo the query before you run it. the query string part that says VALUES ('".$company_name."', looks strange - i think it should be simply: VALUES ('$company_name', ... etc) Link to comment https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/#findComment-505684 Share on other sites More sharing options...
dazz_club Posted March 31, 2008 Author Share Posted March 31, 2008 Hi, Thats weird, because I used the exact same method on another project and it worked. I'll change it now to what you suggested and post back how i got on. cheers again. kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/#findComment-505720 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Share Posted March 31, 2008 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 Link to comment https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/#findComment-505722 Share on other sites More sharing options...
dazz_club Posted March 31, 2008 Author Share Posted March 31, 2008 aaa, nope your eyes are fine, i had an extra variable $telephone. Cheers I never gone be a good developer if i cant see little things like that. cheers again mate . kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/#findComment-505726 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Share Posted March 31, 2008 Ah you beat me to it I posted what it was. The way I test things like that is whack the query into the database and input the values manually and see if it messes up Try that one in the future, saves getting frustrated Glad to see it helped Link to comment https://forums.phpfreaks.com/topic/98825-form-not-entering-data-into-the-database/#findComment-505728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.