开发者

How to redirect link in php code

I'm newbie in PHP.I got this code.

<?
$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();
?>

==================================================================================

If data saved,I want to redirect link to a another page.is this possible??

Thanks in advance.


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();
}


Where you have

print "Data saved";

Send a Location header to tell the browser to go to a different URL

header("Location: http://www.example.com/");

While you're making changes, escape the user input so that when Little Bobby Tables registers, it doesn't break your database.


Yes

header("Location: new-url");

Note that this will only work if you have not emitted output before you get to the header.


header('Location: http://www.php.net');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜