dazzclub Posted March 26, 2008 Share Posted March 26, 2008 Hi people, i have form that submits data to my database by using my enquiry.php script. It works, but there is one thing that i would like to change. if possible i would like to display a thank you note after the form has been submitted. here is the code for my form; --------------------------- <ul class="contactForm" id="topForm"> <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>telephone: <input type="text" name="telephone"></li> </ul> <ul class="contactForm" id="middleForm"> <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="postal_zip_code"></li> </ul> <ul class="contactForm" id="bottomForm"> <li>State: <select name="state" > <option value="Select One" selected="selected">Select One</option> <option value="AB">...</option> <option value="BC">...</option> <option value="WY">...</option> </select> </li> <li> </li> <li>Country: <select name="country" id="country"> <option>Select a country</option> <option>Australia</option> <option>....</option> <option>...</option> <option>...</option> </select> </li> <li> </li> <li>product 0f interest: <select name="product_of_interest"> <option value="Select One" selected="selected">Select One</option> <option>...</option> <option>....</option> <option>...</option> </select> </li> <li>comments:<br /><textarea name="comments" style="height:134px; width:280px;"></textarea></li> <li> </li> <li><input type="submit" name="submit" value="submit" title="Click here to search" ></li> </ul> </form> --------------------------- and here is the enquiry.php script; ------------------------------ <?php require_once("includes/connection.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']; $errors .= (empty($first_name)) ? "<br />You have forgotton to include your first name." : ""; $errors .= (empty($last_name)) ? "<br />You have forgotton to include your surname." : ""; $errors .= (empty($email)) ? "<br />To help you, we require your email." : ""; //need to add country, product and state if (!$errors) { 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', 'xxx', '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, 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(); } ?> <?php echo ($errors) ? "<p>There are errors: $errors</p>" : ""; ?> ------------------------- Would i need to tweak around with this section of the script "....echo $db->affected_rows. 'enquiry entered';....." kind regards Dazzclub --------------------------------------------- Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted March 26, 2008 Share Posted March 26, 2008 Change the bottom From: <?php <?php echo ($errors) ? "<p>There are errors: $errors</p>" : ""; ?> ?> To <?php if (!$errors) { echo "Thanks for your input"; } else { echo "There are errors: ".$errors.""; } ?> Quote Link to comment Share on other sites More sharing options...
dazzclub Posted March 26, 2008 Author Share Posted March 26, 2008 Hi there timmy0320, I should have explained myself clearly. Currently, the form works by submitting the php script. when the user has submitted the form the enquiry.php displays a note. What i would like to achieve is for the form to display a thank on the same page. Somehow combine the script in the contact-us.php. did i make any sense?? Anyhw i will try and combine them now and see how far i get. kind regards Dazzclub Quote Link to comment Share on other sites More sharing options...
dazzclub Posted March 26, 2008 Author Share Posted March 26, 2008 Hi there, I think i amg getting somewhere, i have now mangaed to combine the script with the form so instead of having, contact-us.php and using enquiry.php to insert the details in the database, its all on contact.php. the problem i seem to behaving is that the script will not insert the data in the tables at all. here is what the script looks like <?php require_once("includes/connection.php"); if(isset($_POST['submit'])) { $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(!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); $errors .= (empty($first_name)) ? "<br />You have forgotton to include your first name." : ""; $errors .= (empty($last_name)) ? "<br />You have forgotton to include your surname." : ""; $errors .= (empty($email)) ? "<br />To help you, we require your email." : ""; }else{ $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 = new mysqli('localhost', 'root', 'DARREN', 'drinkpromo'); if (mysqli_connect_errno()) { echo 'error'; exit; $db->close(); } } ?> Any ideas to what i can change?? Quote Link to comment Share on other sites More sharing options...
dazzclub Posted March 26, 2008 Author Share Posted March 26, 2008 Hi all, I have managed to do it, here is what the completed script looks like <?php require_once("includes/connection.php"); if(isset($_POST['submit'])) { $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']; $errors .= (empty($first_name)) ? "<span class=\"emptyFields\">First Name.</span>" : ""; $errors .= (empty($last_name)) ? "<span class=\"emptyFields\">Last name.</span>" : ""; $errors .= (empty($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()) { $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', 'DARREN', 'drinkpromo'); if (mysqli_connect_errno()) { echo 'error'; } $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 'well done'; } } ?> Thanks for all your hellp guys 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.