Good Friday to everyone,
I have set up a form. Once the form is submitted the information is sent to this page (see code) below. I am trying to use an if statement to check if the VIN already exists in the database before it is INSERTed into MySQL. If the vin does exist the user gets an error saying so. If it doesn't exist the ELSE statement INSERTs the information into the database and the user gets a thank you message.
It worked once... but stopped... I may have changed something to mess it up.
<?php
//If Everything Appears to be Okay, the User Sends to the Database by clicking submit
if(isset($_POST['final'])){
$first_name=$_POST[first_name];
$last_name=$_POST[last_name];
$street=$_POST[street];
$city=$_POST[city];
$state=$_POST[state];
$zip_code=$_POST[zip_code];
$phone=$_POST[phone];
$vehicle_year=$_POST[vehicle_year];
$vehicle_make=$_POST[vehicle_make];
$vehicle_model=$_POST[vehicle_model];
$vin=$_POST[vin];
$phone=$_POST[phone];
$date = date('l F jS, Y');
$time = date('g:i A');
$next_month = date('l F jS, Y', strtotime("+28 day", time()));
require ('get_connected.php');
$sql = ("SELECT vin FROM canada");
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
if ($vin == $row['vin']) {
echo "<font color='red'>You request was not submitted.</font> The Vehicle Identification Number $vin is already in our database.";
} else {
require ('get_connected.php');
mysql_query ("INSERT INTO canada (first_name, last_name, street, city, state, zip_code, phone, vehicle_year, vehicle_make, vehicle_model, vin, date, time) VALUES ('$first_name', '$last_name', '$street', '$city', '$state', '$zip_code', '$phone','$vehicle_year', '$vehicle_make', '$vehicle_model', '$vin', '$date', '$time')") or die('Error In Query: '.mysql_error());
echo "<b>Thank You, $first_name $last_name</b><br><p>
Your information was submitted on $date.";
}
}
}
}
?>
Thanks for any help or suggestions.