Sometimes when I hit submit my form data inserts into the database, other times it doesn't. I can't figure out why this is happening. In the code below how do I add an error message that will show me why?
Thanks ever so much!
<?php
// create short variable userIDs
$raceID=$_POST['raceID'];
$userID=$_POST['userID'];
$crewID=$_POST['crewID'];
$typeOfCanoe=$_POST['typeOfCanoe'];
if (!$raceID || !$userID || !$crewID || !$typeOfCanoe) {
echo "You have not entered all the required details.<br />"
."Please go back and try again.";
exit;
}
if (!get_magic_quotes_gpc()) {
$raceID = addslashes($raceID);
$userID = addslashes($userID);
$crewID = addslashes($crewID);
$typeOfCanoe = addslashes($typeOfCanoe);
}
//need to specify fields that you are inserting the data into when it is autoincrement?
$query = "INSERT INTO crewmembers (raceID, userID, crewID, typeOfCanoe) values
('".$raceID."', '".$userID."', '".$crewID."', '".$typeOfCanoe."')";
$result = $db->query($query);
if ($result) {
echo $db->affected_rows." data inserted into database.";
} else {
echo "An error has occurred. The item was not added.";
}
$db->close();
?>