Jump to content

[SOLVED] Keeps inserting in table on refresh


bobahad

Recommended Posts

Hello guys,

 

I created a simple entry form, but the problem is everytime I refresh the page, it keeps adding the same values over and over again.

I just want it to insert it when Add is clicked. Please advice.

Thanks

 

//Query to insert in table

if (isset($_POST['add'])){

$query="INSERT INTO $Table (Type,Make,Model,Year,VIN,Color,Cost,Price,Bought,Link)

    VALUES ('$type','$make','$model','$year','$vin','$color','$cost','$sellingprice','$datebought','$logolink')";

   

 

  if(mysql_db_query($Database,$query,$Link)){

print("<FONT SIZE=\"3\" COLOR=\"Green\">");

print("The car was added successfully!\n");

print("</FONT>");

     

    } else{

   

print("<FONT SIZE=\"3\" COLOR=\"Red\">");

print("The car was not added!\n");

print("</FONT>");

      }

//Close connection

mysql_close($Link);

}

Link to comment
Share on other sites

Instead of

<?php
print("<FONT SIZE=\"3\" COLOR=\"Green\">");
print("The car was added successfully!\n");
print("</FONT>");
?>

use header function, like this:

<?php
header('Location: your.congrats.file');
exit;
?>

When you refresh page, post is being send again, because it's made to do this, so only way to avoid this, is reload page with header function.

In "your.congrats.file" you can place "The car was added successfully!" text and back link.

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.