ianhaney50 Posted June 27, 2015 Share Posted June 27, 2015 Hi I just thought I would test the info form again to make sure it still works and I fill it out and it comes up added to database so I check the database and the only data it has added is the dates into the renewal table, it has not added any data to the visitors table The php page is not displaying any errors Is it ok if anyone can check the code over please <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Information Form - The Tax Elephants"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); ?> <!--CONTENT--> <div id="column-left"> <div class="form"> <form action="" method="post"> <label>Name :</label> <input type="text" name="visitor_name" required="required" placeholder="Please Enter Name"/> <br /><br /> <label>Email :</label> <input type="email" name="visitor_email" required="required" placeholder="john123@gmail.com"/> <br/><br /> <label>Address Line 1 :</label> <input type="text" name="visitor_firstline" required="required" placeholder="Please Enter First Line of your address"/> <br><br> <label>Address Line 2 :</label> <input type="text" name="visitor_secondline" required="required" placeholder="Please Enter Second Line of your address"/> <br><br> <label>Town :</label> <input type="text" name="visitor_town" required="required" placeholder="Please Enter your Town"/> <br><br> <label>County :</label> <input type="text" name="visitor_county" required="required" placeholder="Please Enter Your County"/> <br/><br /> <label>Postcode :</label> <input type="text" name="visitor_postcode" required="required" placeholder="Please Enter Your Postcode"/> <br><br> <label>Telephone Number :</label> <input type="text" name="visitor_tel" required="required" placeholder="Please Enter Your Telephone Number"/> <br><br> <label>Mobile Number :</label> <input type="text" name="visitor_mobile" required="required" placeholder="Please Enter Your Mobile Number"/> <br><br> <label>Model of Car/Van :</label> <input type="text" name="visitor_model" required="required" placeholder="Please Enter the Model of your Car or Van"/> <br><br> <label>License Plate Number :</label> <input type="text" name="visitor_plate" required="required" placeholder="Please Enter your License Number Plate"/> <br><br> <label>Car Tax Renewal Date :</label> <input type="text" id="datepicker" name="visitor_tax" required="required" placeholder="Please Enter your Car Tax Renewal Date"/> <br><br> <label>MOT Expiry Date :</label> <input type="text" id="datepicker2" name="visitor_mot" required="required" placeholder="Please Enter your MOT Expiry Date"/> <br><br> <label>Insurance Expiry Date :</label> <input type="text" id="datepicker3" name="visitor_insurance" required="required" placeholder="Please Enter your Insurance Expiry Date"/> <br><br> <div class="box"> <label>I agree to the <a class="button" href="#popup1">terms</a></label> </div> <input type="checkbox" class="checkbox" id="the-terms" value="I Agree"> <div id="popup1" class="overlay"> <div class="popup"> <h2>Terms</h2> <a class="close" href="#">×</a> <div class="content"> TERMS TEXT. </div> </div> </div> <br /><br /> <input type="submit" value=" Submit " name="submit" disabled="disabled" id="submitBtn" /> </form> </div> </div> <div id="column-right"> </div> <!--CONTENT--> <script> $(document).ready(function() { var the_terms = $("#the-terms"); the_terms.click(function() { if ($(this).is(":checked")) { $("#submitBtn").removeAttr("disabled"); } else { $("#submitBtn").attr("disabled", "disabled"); } }); }); </script> <?php if(isset($_POST["submit"])){ $servername = ""; $username = ""; $password = ""; $dbname = ""; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // escape variables for security $visitor_name = mysqli_real_escape_string($conn, $_POST['visitor_name']); $visitor_email = mysqli_real_escape_string($conn, $_POST['visitor_email']); $visitor_firstline = mysqli_real_escape_string($conn, $_POST['visitor_firstline']); $visitor_secondline = mysqli_real_escape_string($conn, $_POST['visitor_secondline']); $visitor_town = mysqli_real_escape_string($conn, $_POST['visitor_town']); $visitor_county = mysqli_real_escape_string($conn, $_POST['visitor_county']); $visitor_postcode = mysqli_real_escape_string($conn, $_POST['visitor_postcode']); $visitor_tel = mysqli_real_escape_string($conn, $_POST['visitor_tel']); $visitor_mobile = mysqli_real_escape_string($conn, $_POST['visitor_mobile']); $visitor_model = mysqli_real_escape_string($conn, $_POST['visitor_model']); $visitor_plate = mysqli_real_escape_string($conn, $_POST['visitor_plate']); $sql = "INSERT INTO visitors (visitor_name, visitor_email, visitor_firstline, visitor_secondline,visitor_town, visitor_county, visitor_postcode, visitor_tel, visitor_mobile, visitor_model, visitor_plate) VALUES ('$visitor_name', '$visitor_email', '$visitor_firstline', '$visitor_secondline', '$visitor_town', '$visitor_county', '$visitor_postcode', '$visitor_tel', '$visitor_mobile', '$visitor_model', '$visitor_plate')"; $visitor_id = $conn->insert_id; $insurance_date = date('Y-m-d', strtotime($_POST['visitor_insurance'])); $mot_date = date('Y-m-d', strtotime($_POST['visitor_mot'])); $tax_date = date('Y-m-d', strtotime($_POST['visitor_tax'])); $sql = "INSERT INTO renewal (visitor_id, item_id, renewal_date) VALUES ($visitor_id, 1, '$insurance_date'), ($visitor_id, 2, '$mot_date'), ($visitor_id, 3, '$tax_date')"; /*echo "<pre>$sql</pre>";*/ /*$conn->query($sql);*/ $result = $conn->query($sql); if ($result !== false) { echo "<script type= 'text/javascript'>alert('Your Information has been added successfully to our database');</script>"; } else { echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>"; } $conn->close(); } ?> <?php include( 'includes/footer.php' ); ?> It seems to be skipping past the INSERT INTO visitors sql and jumps to the second INSERT INTO renewal? Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/ Share on other sites More sharing options...
Solution ginerjm Posted June 27, 2015 Solution Share Posted June 27, 2015 IN your second query you call the 'query' function. In your first query you never made a call to the query function, hence no update. Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515112 Share on other sites More sharing options...
ianhaney50 Posted June 27, 2015 Author Share Posted June 27, 2015 Ahh guess that is this line after the second query? $result = $conn->query($sql); so I need the same line after the first query? Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515113 Share on other sites More sharing options...
ianhaney50 Posted June 27, 2015 Author Share Posted June 27, 2015 Sorted, I added in $result = $conn->query($sql); just under the first query and has added it in the database sorry for being stupid thank you for replying though, appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515114 Share on other sites More sharing options...
ginerjm Posted June 28, 2015 Share Posted June 28, 2015 So this question should be marked 'answered'? Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515151 Share on other sites More sharing options...
ianhaney50 Posted June 28, 2015 Author Share Posted June 28, 2015 How do I mark it as answered I can't see anywhere on this page to mark it as answered or is it on the main page with the list of posts? Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515152 Share on other sites More sharing options...
ginerjm Posted June 28, 2015 Share Posted June 28, 2015 I think a link should show up for you only since it is your post. Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515156 Share on other sites More sharing options...
Ch0cu3r Posted June 28, 2015 Share Posted June 28, 2015 There should be a Best Answer button at the bottom right handside of each post Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515157 Share on other sites More sharing options...
ianhaney50 Posted June 28, 2015 Author Share Posted June 28, 2015 ahh cool done it Quote Link to comment https://forums.phpfreaks.com/topic/297069-info-form-not-adding-to-database/#findComment-1515159 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.