manalnor Posted March 26, 2011 Share Posted March 26, 2011 Hello dear friends, I've very annoying problem :'( my website is for child drawing (draw.php) after child do drawing will click on submit (form) by sending it to another page (thanks.php) | | | | data will be submitted to database and gives message saying ( thank you for ...blah blah blah) here is the problem if he refresh the page , it will also add entry to the database so imagine if someone did many many refresh, i will get many many empty entry into database how to stop this ? here is simple code based on this problem <form name="frm" method="post" action="thanks.php"> <input type="text" name="name" id="name" value=""> <input type="text" name="email" id="email" value=""> <button type="submit">Submit</button> </form> and the (thanks.php) file code *assume we have connection to db $sql = "INSERT INTO $table (name, email) VALUES ('$name', '$email')"; mysql_query($sql, $conn) or die(mysql_error()); echo "Thank you kid..nice drawing"; now my problem if (thanks.php) got refreshed it will also will add empty entry to database can anyone please help me how to stop it. Link to comment https://forums.phpfreaks.com/topic/231764-empty-entry-on-reload-page/ Share on other sites More sharing options...
vulcandth Posted March 26, 2011 Share Posted March 26, 2011 In you thanks script.. if you have a if ($_POST['name'] != '') { //SQL here } Basically that says, if he doesn't have any information in that field submitted.. it won't submit anything. I also recommend querying the database to make sure that he hasn't submitted anything before. Link to comment https://forums.phpfreaks.com/topic/231764-empty-entry-on-reload-page/#findComment-1192463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.