开发者

Refresh PHP page once only when called

I have a php which would check for certain value if it exists in a mysql database. If the value does not exists, it would simply add the value and refresh the page once to load the page again and now it has a value in the database, would go ahead to add other values. How do I refresh page just 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
?>

There's the comment to refresh page below after mysql close command.


Refresh it right after insert with

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

Btw, read a little about sql injections

Also - mysql_close() is pointless there.


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


if you need to print the data that you just have entered try this

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

mi apologizes if is wrong , im a begginer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜