仅在调用时刷新 PHP 页面一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4362916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh PHP page once only when called
提问by thotheolh
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,它会检查某个值是否存在于 mysql 数据库中。如果该值不存在,它会简单地添加该值并刷新页面一次以再次加载页面,现在它在数据库中有一个值,将继续添加其他值。如何在调用时只刷新一次页面?
<?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 命令之后,下面有刷新页面的注释。
回答by zerkms
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()
在那里毫无意义。
回答by m.qayyum
if(check=1)
{
echo "\"<meta http-equiv=\"refresh\" content=\"2;url=http://yourwebsite.com/\">\"\n";
}
回答by Ubaldo Arrazola
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
如果错了,我道歉,我是初学者