suttercain Posted April 6, 2007 Share Posted April 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 6, 2007 Share Posted April 6, 2007 what happens if the win isnt found and you do if ($vin == $row['vin']) { that doesnt cause an error? Quote Link to comment Share on other sites More sharing options...
suttercain Posted April 6, 2007 Author Share Posted April 6, 2007 The else statement should then process it... correct? } 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."; Or am I way off base? Quote Link to comment Share on other sites More sharing options...
suttercain Posted April 6, 2007 Author Share Posted April 6, 2007 I have looked over this code 10 times and it appears correct to me. Can anyone tell if something is off? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 6, 2007 Share Posted April 6, 2007 the problem is your query SELECT vin FROM canada YOu need to add a where clause and actually check fo rthe vin, otherwise you're getting all of the rows back in the table 'SELECT vin FROM canada WHERE vin = '.$vin; Quote Link to comment Share on other sites More sharing options...
neel_basu Posted April 7, 2007 Share Posted April 7, 2007 If you are trying to do something like Check Aviliability. Its the best for you. http://zigmoyd.sourceforge.net/man/ums.php#check_avilability Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.