dazz_club Posted March 14, 2008 Share Posted March 14, 2008 Hi people i have a contact form on my site, the the users fill in and then there is a php script that inserts the data into the write table. currently it is not working and i have been at it for over an hour and my eyes are hurting.. here us my html form --------------------- <form method="post" action="enquiry.php"> <ul class="contactForm"> <li>First name: <input type="text" name="first_name"></li> <li>Last name: <input type="text" name="last_name"></li> <li>Email: <input type="text" name="email"></li> <li>Tel: <input type="text" name="telephone"></li> <li> </li> <li>Company: <input type="text" name="company"></li> <li>Address: <input type="text" name="address"></li> <li>Address 1: <input type="text" name="address_a"></li> <li>Address 2: <input type="text" name="address_b"></li> <li>Address 3: <input type="text" name="address_c"></li> <li>Town: <input type="text" name="town"></li> <li>City: <input type="text" name="city"></li> <li>Post / Zip code: <input type="text" name="post_zip_code"></li> <li>State Province: <select name="state"> <option value="Select One" selected="selected">Select One</option> <option value="AB">AB</option> <option value="WY">WY</option> </select> </li> <li>Country: <select name="country" > <option>Select a country</option> <option>Australia</option> <option>UK</option> </select> </li> <li> </li> <li>Product of interest: <select name="product_of_interest"> <option value="Select One" selected="selected">Select One</option> <option>Game Cards and Stickers</option> <option>Beer Mats and Coasters</option> <option>Thermometers</option> <option>Stirrers</option> <option>Glassware</option> <option>P.O.S</option> <option>Labels and Packaging</option> </select> </li> <li>comments:<br /> <input type="text" name="comments" style="height:134px; width:220px;"></li> <li><input type="submit" name="submit" value="submit" title="Click here to search"></li> </ul> </form> --------------------- and here is my php script ----------------------- <?php require_once("includes/connection.php"); ?> <?php $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $email=$_POST['email']; $telephone=$_POST['telephone']; $address=$_POST['address']; $address_a=$_POST['address_a']; $address_b=$_POST['address_b']; $address_c=$_POST['address_c']; $town=$_POST['town']; $post_zip_code=$_POST['post_zip_code']; $city=$_POST['city']; $state=$_POST['state']; $country=$_POST['country']; $product_of_interest=$_POST['product_of_interest']; $comments=$_POST['comments']; if (!$first_name || !$last_name || !$email || !$telephone || !$address || !$address_a || !$address_b || !$address_c || !$town || !$post_zip_code || !$city || $state || $country || $product_of_interest || $comments) { echo 'dick head you have forgotton something'; exit; } if (!get_magic_quotes_gpc()) { $first_name = addslahes(first_name); $last_name = addslahes(last_name); $email = addslahes(email); $telephone = addslahes(telephone); $address = addslahes(address); $address_a = addslahes(address_a); $address_b = addslahes(address_b); $address_c = addslahes(address_c); $town = addslahes(town); $post_zip_code = addslahes(post_zip_code); $city = addslahes(city); $state = addslahes(state); $country = addslahes(country); $product_of_interest = addslahes(product_of_interest); $comments = addslahes(comments); } @ $db = new mysqli('localhost', 'root', 'xx', 'xxx'); if (mysqli_connect_errno()) { echo 'error'; exit; } $query = "INSERT INTO enquiries (first_name, last_name, email, telephone, company, address, address_a, address_b, address_c, town, city, post_zip_code, state, country, product_of_interest, comments) VALUES ('".$first_name."', '".$last_name."', '".$email."', '".$telephone."', '".$address."', '".$address_a."', '".$address_b."', '".$address_c."', '".$town."', '".$post_zip_code."', '".$city."', '".$state."', '".$country."', '".$product_of_interest."', '".$comments."')"; $result = $db->query($query); if ($result) echo $db->affected_rows. 'enquiry entered'; $db->close(); ?> ----------------------- I have managed to see where it stops working, i put an echo displaying 'dick head you have forgotton something', which currently it shows every time i press submit. any help would be great. kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
affordit Posted March 14, 2008 Share Posted March 14, 2008 This is just a guess but I would try changing this line $post_zip_code=$_POST['post_zip_code']; To this $postal_zip_code=$_POST['postal_zip_code']; And don't forget to change it in your form code Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 14, 2008 Share Posted March 14, 2008 You'll also have to update the form to have the corresponding name attribute as well if you do that. EDIT: @affordit: Did your post have that at the bottom the first time? Quote Link to comment Share on other sites More sharing options...
dazz_club Posted March 14, 2008 Author Share Posted March 14, 2008 aa, i see why you thought that affordit, i have just changed the script along with the form and it still stops at "echo 'dick head you have forgottom something'; I have a coffee and come back to this. Cheers guys kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 14, 2008 Share Posted March 14, 2008 Try? if (empty($first_name) || empty($last_name) || empty($email) || empty($telephone) || empty($address) || empty($address_a) || empty($address_b) || empty($address_c) || empty($town) || empty($post_zip_code) || empty($city) || $state=="Select One" || $country=="Select One" || $product_of_interest=="Select One" || empty($comments)) { Also, make sure that the select menus have values for all options so that you can check against them. And please use tags when posting code. Quote Link to comment Share on other sites More sharing options...
dazz_club Posted March 14, 2008 Author Share Posted March 14, 2008 after reading your post charlieholder, i thought i`d make myself some coffee have a break and look at it with fresh eyes. And behold, those fresh eyes started to work. i looked closer at my script and had noticed i spelt slashes incorrectly and also forgot the "$" aswell, getting somewhere i thought. SO i then removed all the input fields leaving just the first name along with correcting the php script, all is fine. so what i am doing now is building and testing the form as i go along, so far so good. cheers for your help guys. kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
dazz_club Posted March 14, 2008 Author Share Posted March 14, 2008 Ok guys, The form is now inputting all of the data, so its complete. Well phase 1 is complete, what i plan to do next is have the form submit to an email address aswell and i also need to have some validation on this form aswell . so below is the finished script; <?php require_once("includes/connection.php"); ?> <?php $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $email=$_POST['email']; $telephone=$_POST['telephone']; $company=$_POST['company']; $address=$_POST['address']; $address_a=$_POST['address_a']; $address_b=$_POST['address_b']; $address_c=$_POST['address_c']; $town=$_POST['town']; $city=$_POST['city']; $postal_zip_code=$_POST['postal_zip_code']; $state=$_POST['state']; $country=$_POST['country']; $product_of_interest=$_POST['product_of_interest']; $comments=$_POST['comments']; if (!$first_name) { echo 'dick head you have forgotton something'; exit; } if (!get_magic_quotes_gpc()) { $first_name = addslashes($first_name); $last_name = addslashes($last_name); $email = addslashes($email); $telephone= addslashes($telephone); $company= addslashes($company); $address= addslashes($address); $address_a= addslashes($address_a); $address_b= addslashes($address_b); $address_c= addslashes($address_c); $town= addslashes($town); $city= addslashes($city); $postal_zip_code= addslashes($postal_zip_code); $state= addslashes($state); $country= addslashes($country); $product_of_interest= addslashes($product_of_interest); $comments= addslashes($comments); } @ $db = new mysqli('localhost', 'root', 'xx', 'xx'); if (mysqli_connect_errno()) { echo 'error'; exit; } $query = " INSERT INTO enquiries (first_name, last_name, email, telephone, company, address, address_a, address_b, address_c, town, city, postal_zip_code, state, country, product_of_interest, comments ) VALUES ('".$first_name."', '".$last_name."', '".$email."', '".$telephone."', '".$company."', '".$address."', '".$address_a."', '".$address_b."', '".$address_c."', '".$town."', '".$city."', '".$postal_zip_code."', '".$state."', '".$country."', '".$product_of_interest."', '".$comments."')"; $result = $db->query($query); if ($result) echo $db->affected_rows. 'enquiry entered'; $db->close(); ?> kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 14, 2008 Share Posted March 14, 2008 Did you mean to only check the first name? if (!$first_name) { echo 'dick head you have forgotten something'; exit; } Well, you can use mail() to accomplish that. There are TONS of tutorials and examples on the internet as well as in this forum. What I do for errors is something like this: <?php $var1 = $_POST['var1']; $var2 = $_POST['var2']; $var3 = $_POST['var3']; // error checking $errors .= (empty($va1)) ? "<br />Error with var1." : ""; $errors .= (empty($va2)) ? "<br />Error with var2." : ""; $errors .= (empty($va3)) ? "<br />Error with var3." : ""; if (!$errors) { //use mail function } ?> <?php echo ($errors) ? "<p>There are errors: $errors</p>" : ""; ?> <form> ... That's one one type of error checking. A check to make sure that they in face typed something in. You kind of already have that setup. There are many different things that you'll want to check for. Using preg_match() to do some of them may be a good idea. Just do some research. Quote Link to comment Share on other sites More sharing options...
dazz_club Posted March 15, 2008 Author Share Posted March 15, 2008 Currently, i have put a check to see if any of the variables are empty if they are, it will echo 'you have forgotton something' if (!$first_name || !$last_name || !$email || !$telephone || !$company || !$address || !$address_a || !$address_b || !$address_c || !$town || !$city || !$postal_zip_code || !$comments) { echo 'you have forgotton something'; exit; } Using your code i will make it so the name of the field shows up if empty, be more sepcific , echo 'you have forgotton you last name'. kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
dazz_club Posted March 17, 2008 Author Share Posted March 17, 2008 Hi there charlieholder, I have successfully inserted your code into mine to see if a specific field is empty on my contact form. Many thanks Kind regards Dazzclub Quote Link to comment 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.