我是PHP新手。我得到了这个代码。
<?
$connection=mysql_connect("","","");
if(!$connection)
{
die("Database Connection Failed: " . mysql_error());
}
//Select a database to use
$db=mysql_select_db('vss',$connection);
if(!$db)
{
die("Database Selection Failed: " . mysql_error());
}
$class=$_POST['class'];
$section=$_POST['section'];
$roll=$_POST['roll'];
mysql_query("INSERT INTO student_class SET
class='$class',
section='$section',
roll='$roll'");
print"Data Saved";//If data saved,I want to redirect link to a another page
mysql_close();
?>
==================================================================================
如果数据保存,我想重定向链接到另一个页面。这可能吗?
try this:
$qry = mysql_query("INSERT INTO student_class(class, section, roll) VALUES('$class', '$section','$roll')", $connection);
if($qry){
header("Location: nextPage.php");
exit();
}else{
echo "Inserting data fail. <hr />".mysql_error();
}
哪里有
print "Data saved";
发送一个Location头,告诉浏览器转到另一个URL
header("Location: http://www.example.com/");
当您进行更改时,转义用户输入,以便当Little Bobby Tables注册时,它不会破坏您的数据库。
是
header("Location: new-url");
请注意,只有在到达标题之前没有发出输出时,这才会起作用。
header('Location: http://www.php.net');