plodos Posted August 25, 2008 Share Posted August 25, 2008 form.html <form action="a.php" method="post"> <table border="0" bgcolor="#ececec" cellspacing="5"> <tr> <td>Name</td><td> <input name="name" type="text" id="name" size="25"/></td> </tr> <tr> <td>Surname</td><td> <input name="surname" type="text" id="surname" size="25"/></td> </tr> </table> </form> a.php <?php include("dbconfig.php"); $name =mysql_real_escape_string($_POST['name']); $surname = mysql_real_escape_string($_POST['surname']); $add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname') "); if($add_person) { include('ok.html'); } else { echo "Error"; } ?> This is my sample code, I want to improve that, how can I block the repeated data.... If the person click the Register button 3 times, database is saving the person information 3 times, and when I listed, query show me 3 same information.... what must I do ? I want to see unique information for each person....I want to block multiple records, please help... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 25, 2008 Share Posted August 25, 2008 Check to see if the record is in the database before inserting it. Ken Quote Link to comment Share on other sites More sharing options...
revraz Posted August 25, 2008 Share Posted August 25, 2008 Also, maybe create a Username field as well and make it unique. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 So... It would look like this: include("dbconfig.php"); $name =mysql_real_escape_string($_POST['name']); $surname = mysql_real_escape_string($_POST['surname']); $sql = mysql_query("SELECT * FROM person WHERE fname = '$name' AND lname = '$surname'"); if(mysql_num_rows($sql) < 1){ $add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname') "); if($add_person){ include('ok.html'); } else{ echo "Error"; } } Quote Link to comment Share on other sites More sharing options...
revraz Posted August 25, 2008 Share Posted August 25, 2008 I think you mean to make that == 0 not greater than 0, since that means they exist. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 25, 2008 Share Posted August 25, 2008 I think you mean to make that == 0 not greater than 0, since that means they exist. I modified it before this post Quote Link to comment Share on other sites More sharing options...
plodos Posted August 25, 2008 Author Share Posted August 25, 2008 thank you... I used this system include("dbconfig.php"); $name =mysql_real_escape_string($_POST['name']); $surname = mysql_real_escape_string($_POST['surname']); $sql = mysql_query("SELECT * FROM person WHERE fname = '$name' AND lname = '$surname'"); if(mysql_num_rows($sql) < 1){ $add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname') "); if($add_person){ include('ok.html'); } else echo "Error"; } } but I have one more question:) phpmyadmin recorded the empty data....If the user click register 5 times...mysql is saving the first data with full information and other 4 fields are empty like 1 nokia mobile 2 3 4 5 6 samsung mobile 7 8 sony mobile how can I block the emyty data? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 25, 2008 Share Posted August 25, 2008 Those values are not even in your code you posted, so that must be coming from somewhere else. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.