简体   繁体   English

仅在调用时刷新PHP页面一次

[英]Refresh PHP page once only when called

I have a php which would check for certain value if it exists in a mysql database. 我有一个php,如果它存在于mysql数据库中,它将检查某些值。 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. 在mysql close命令之后有关于刷新页面的注释。

Refresh it right after insert with 插入后立即刷新

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

Btw, read a little about sql injections 顺便说一句,阅读一些关于sql注入的内容

Also - mysql_close() is pointless there. 另外 - mysql_close()在那里毫无意义。

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 mi道歉,如果是错的,我是一个乞丐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM