Jump to content

Empty Entry On Reload Page


manalnor

Recommended Posts

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

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