Jump to content

prevent duplicate insert on array.


turpentyne

Recommended Posts

I'm trying to prevent the reinsertion of data if a user refreshes a page. Tried using header() to take them to a new page but I'm using sessions, and it gives an error. Now I'm doing a basic check to see if the field exists before insert...

 

but I'm inserting arrays. Not sure if I've got this right. Would this work.

 

 
if(sizeof($_POST['fname'])) {
// loop through array 
$number = count($fname); 
for ($i=0; $i<$number; $i++) 
{ 
   $fnames = $fname[$i]; 
    $lnames = $lname[$i];
    $phones = $phone[$i]; 
    $emails = $email[$i];
    $bdates = $bdate[$i];
    $bdates2 = $bdate2[$i];
    $bdates3 = $bdate3[$i];
    $wids = $wid[$i];
    $rids = $rid[$i];	

$number_of_rows = mysql_num_rows(mysql_query("SELECT * FROM tbl_attendees WHERE attendee_fname='$fnames' AND  attendee_lname='$lnames' AND attendee_registrationid='$rid'"));

if($number_of_rows > 0) { // nothing to do. Just want to reload the page without running query insert

} else {

		$query_insertItemWorkshop = "INSERT INTO tbl_attendees (attendee_fname, attendee_lname, attendee_registrationid, workshop_id, attendee_email, attendee_telephone, attendee_bday, attendee_bmonth, attendee_byear) VALUES ('$fnames', '$lnames', '$reg_alone', '$wids', '$emails', '$phones', '$bdates', '$bdates2', '$bdates3')";


		$dberror = "";
		$ret = mysql_query($query_insertItemWorkshop);


}


<!-- rest of page --> 

Link to comment
https://forums.phpfreaks.com/topic/259137-prevent-duplicate-insert-on-array/
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.