Hi I have this code shown below. This works great but every so often the data does not get added to the database. What is the best way to ensure that the data gets added to the database. What I think should happen is that on an error it tries again maybe every 15 seconds for say 3 times. Let me know if you don't agree.
Can anybody show me the php code I need to add and where I should add it. I'm a little out of my depth but I'm thinking that the php knows when it's failed as there is "if ($conn->connect_error)" in the code.
I'm also concerned that the data does not get added multiple times.
Please let me know if this is more complicated than I'm thinking. Any help, comments are welcome.
<?php
///////////////////////////////////////////////
//////////////////// Login ////////////////////
///////////////////////////////////////////////
$servername = "*******";
$username = "*******";
$password = "*******";
$dbname = "*******";
///////////////////////////////////////////////
/////////////// Get vars //////////////////////
///////////////////////////////////////////////
$identifier = $_REQUEST['identifier'];
$paid = "Not Paid";
$cartAmount = $_REQUEST['cartAmount'];
$cartMore = $_REQUEST['cartMore'];
$cartLink = $_REQUEST['cartLink'];
$cartImage = $_REQUEST['cartImage'];
$cartSelected = $_REQUEST['cartSelected'];
$cartName = $_REQUEST['cartName'];
$cartQuantity = $_REQUEST['cartQuantity'];
$shippedDate = $_REQUEST['shippedDate'];
$myNote = $_REQUEST['myNote'];
///////////////////////////////////////////////
///////////// Create connection ///////////////
///////////////////////////////////////////////
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
///////////////////////////////////////////////
///////////// add vars to data base /////////////
///////////////////////////////////////////////
$sql = "INSERT INTO customers (cartAmount, cartMore, cartLink, cartImage, cartSelected, cartName, cartQuantity, identifier, paid, shipped_date, myNote)
VALUES ('$cartAmount', '$cartMore', '$cartLink', '$cartImage', '$cartSelected', '$cartName', '$cartQuantity', '$identifier', '$paid', '$shippedDate', '$myNote')";
if ($conn->query($sql) === TRUE) {
echo $cartAmount . "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
echo "Connected successfully";
?>