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);

}

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.

Archived

This topic is now archived and is closed to further replies.

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