Insert into database check uniqueness
bkeep
Status: Curious
Joined: 12 Mar 2006
Posts: 9
Reply Quote
hello again tis me got a question about inserting into a database table the current code i have in the function is

:: Code ::

           if ($points>=$set_match_val)
           {
              $sql = "insert into matchprofiles (username_p1,username_p2,score,highest) values ('".$for_user ."', '$username','$points','$highest')";
              $res_ins = query($sql);
              //echo $sql . "<br>";
           
           }

this code inserts the info into the database just fine except it allows the users to submit the same data over and over i would like it to just insert one record then if they come back and use the function again have it check for a record that exists would it be better to delete all the existing records that match username first then insert as new or would a check to see if the username exists then an error message or any other thoughts on this would be helpful

Thanks for any insight
Regards,
Brandon
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
I would do an error message if exists, then add a feature for the user to update their information if required. Which means a form somewhere for them to change their settings/features etc.

I made a friend of mine a user info program for his site, and that's how I handle that situation, if it exists, error message saying they already are signed up, but there is another page where they can update their information if they want. That works well for us.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours