Refresh the PHP page once only on invocation

I have php that will check for a specific value if it exists in the mysql database. If the value does not exist, it will simply add the value and refresh the page once to reload the page, and now it has a value in the database, will add other values. How to refresh a page only once when it is called?

<?php
 $sname = "W3 schools C# tutorials";//$_POST["sitename"];
 $stype = "C#";//$_POST["sitetype"];
 $saddy = "www.w3schools.com";//$_POST["siteaddress"];
 $scomm = "W3 schools C# tutorials";//$_POST["sitecomment"];

 $conn = mysql_connect("localhost","root","password");

 if(!$conn){
   die("Could not connect: ".mysql_error());
 } else {
   mysql_select_db("bookmarks",$conn);
   $rs = mysql_query("select TypeId from bookmarktypes where TypeName = '$stype'");
   $row = mysql_fetch_array($rs);
   if($row > 0 ){
     //Data found, continue to add...
   } else {
    //No data... insert a valid one
    $rs = mysql_query("insert into bookmarktypes (TypeName) values ('$stype')");
    if (!$rs){
      die('Error: ' . mysql_error());
    } else {
    //echo "inserted new type data...";
    }
    //echo "</html>";
    } 
  }
  mysql_close($conn);
  //Refresh page once
?>

Here is a comment to refresh the page below after the mysql close command.

+3
source share
3 answers

Update it immediately after insertion with

header('Location: url here');
exit;

Btw, read a little about sql injections

Also - mysql_close()there is no point.

+8
source
if(check=1)
{    
echo "\"<meta http-equiv=\"refresh\" content=\"2;url=http://yourwebsite.com/\">\"\n";
}
+2
source

,

header('Location: YourShowDataPage.php?id='.$_POST['id_dataEntered'])

mi , , im the begginer

0

Source: https://habr.com/ru/post/1778660/


All Articles