U
U
Uzair Izha2015-11-14 14:29:41
PHP
Uzair Izha, 2015-11-14 14:29:41

How to properly handle post and add to database?

In general, here's the thing
. I have a form with the post method on the ok.php page, by clicking on submit, it reloads to the same ok.php page where it is added to the database. It is added to the database, everything is fine, but the problem is that when this page is updated, the same data is sent to the database. How to build a condition so that a request does not go to the database just from updating the page.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valera Karmanov, 2015-11-14
@UZEIR

After the SQL query to add a record to the database, make a redirect to the page with the form...
Can you see the form code???

J
javanub, 2015-11-14
@javanub

I think everything is clear here

if (isset($_POST['submit'])) 
{
  $user= $_POST['username'];
  $email = $_POST['useremail'];
  $pass= $_POST['password']; 

  mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

}
//best outside the if statement so user isn't stuck on a white blank page.
header("location: landing_page.php");
exit;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question