Jump to content

Checking id exists


zimmo

Recommended Posts

I have my code now working thanks to guys off here. Next step is for me to extend this, and not sure the best way to do this.

 

This is the scenario:

User fills in the first page of the form, if they miss any data that is required it asks them for it.

Once done, they click the submit button.

This then enters the information into the database.

As the id field is auto_increment, it creates a new "id" number for the insert.

 

The problem:

The user hits the back button on the browser and then submits the data AGAIN

This would then create another insert but with the next "id" number

So we then have 2 records the same with different id numbers.

 

I need to be able to check that they have entered only once and not allow them again?

My problem is that it creates the id on the first entry, how can php check this?

 

Code for the php insert to mysql (taken from file)

if (!$error) {
	# setup SQL statement
	$SQL = " INSERT INTO dtable ";
	$SQL = $SQL . " (venue_name, address_1, address_2, address_3, town, county, postcode, email, telephone_1, telephone_2, fax) VALUES ";
	$SQL = $SQL . " ('$venue_name', '$address_1', '$address_2', '$address_3', '$town', '$county', '$postcode', '$email', '$telephone_1', '$telephone_2', '$fax') ";

	#execute SQL statement
	$result = mysql_db_query( dbname,"$SQL",$connection );

	# check for error
	if (!$result) { 
	 echo("ERROR: " . mysql_error() . "\n$SQL\n");	 
	} else {
	$id = mysql_insert_id();
	header("Location: http://www.domain.com/admin/next_contact.html?fishery_id=$id");
	exit;
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/198150-checking-id-exists/
Share on other sites

Use the session then. You could also store the users IP Address with the row, and do a check to see if that IP has already submitted a row before.

 

Be aware though that some ISP's change the users IP often. With the session method there's no guarantee either because it would only take a clear of the cookies to get a new session ID.

Link to comment
https://forums.phpfreaks.com/topic/198150-checking-id-exists/#findComment-1039710
Share on other sites

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.