Jump to content

Refreshing the database??


ali_2kool2002

Recommended Posts

well im inserting a new record with a value id say "2" in one of the fields

but if i click the back button on the web browser, and then go forward to the same original php page that inserts the record, it still thinks that the record i added has not beed added and so adds another record with the same value...

 

the problem is i dont want it to be able to insert records if the id 2 allready exists in the table, so was wondering if i could refresh the database somehow and then check if it exists.

 

hope this helps  :'( :'(

      <?php
require_once('mysql_connect.php');

if (isset($_POST['submitted'])) {



				if (empty ( $_POST['driverId'] ) ){
					echo "empty";
					}
					else{
					$driverId = $_POST['driverId'];
					$check_if_already_exists =   "select driverId from delivery
													where driverId = '$driverId'";

        			$check_result = mysql_query($check_if_already_exists) or die ("couldnt execute query");

					if (mysql_num_rows($check_result) >1) {
						?>
					       <script language="Javascript">
							alert ( "driver all ready exists")
							</script>
				        <?

						}
						else{
					$driverId = $_POST['driverId'];
					$get_Name = "select driverName from driver
								where driverId = $driverId";
					$get_name_res = mysql_query($get_Name) or die(mysql_error());

					while ($results = mysql_fetch_array($get_name_res, MYSQL_ASSOC))
						{ 
						echo '<tr><td align="center"><b>You have selected : </b> ' . $results['driverName'] . '</td></tr><br /> ';


						echo "new delivery created";

						//INSERT NEW DELIVERY RECORD
						$insert_query =   "INSERT INTO `delivery` (`deliveryId`, `driverId`, `deliveryDate`)
								   VALUES (NULL, '$driverId ', now())";
        				$result = mysql_query($insert_query) or die ("couldnt execute query");
						echo "<B> new delivery created </B><br />";

					}
					}

sorri it is quite a big chunk of code but ,, if i refresh the actual page (ie browser) 2 times, then after that the sql databse updates and the php recognises that there is an existing record with the same driver id ... i jus thought someone may know if there is a code in php to update mysql databse straight after inserting a record..?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.