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... Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/ 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 Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624952 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. Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624955 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"; } } Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624960 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. Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624963 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 Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624965 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? Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-624999 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. Link to comment https://forums.phpfreaks.com/topic/121232-database-is-saving-the-person-information-lots-of-times/#findComment-625002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.