I have 2 pages. After the user inserts all their info on page 1, they go to page 2. All the inputted information gets correctly stored in $_POST so I can access it in the next page. I can also insert into mysql database just fine no problem. The thing I'm trying to do is to ONLY execute the insert into the database code IF they click the submit button on the second page. I tried doing this:
Page2.php
<script>
$(document).ready(function(e) {
$("#PaySubmit").click(function() {
$.ajax({
url: 'Insert.php'
});
});
});
</script>
<input type="submit" name="PaySubmit" id="PaySubmit" value="Continue"/>
Insert.php
try {
$link = new PDO('mysql:host=****;dbname=****;charset=UTF-8','****','****');
$first = $_POST["fname"];
$last = $_POST["lname"];
$stmt = $link -> prepare("INSERT INTO Conference (`First Name`, `Last Name`) VALUES (:first, :last)");
$stmt->bindParam(':first', $first);
$stmt->bindParam(':last', $last);
$stmt->execute();
} catch(PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
The problem is, when you click submit on the 2nd page $_POST gets replaced with data from the second page, so I no longer have access to the 1st page's data. Any ideas on how to go about this?