Jump to content

info form not adding to database


ianhaney50
Go to solution Solved by ginerjm,

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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