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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.