我的 PHP 代码出错了。我的想法是检查数据库中是否存在用户名和密码,然后将其重定向到 URL。
在此处输入代码我创建了两个页面。一个是索引,另一个是重定向。重定向代码出现问题。
<!DOCTYPE html>
<html>
<body>
<?php
//echo $_POST['uname'];
//echo $_REQUEST['uname'];
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];
//echo $_POST['pwd'];
//echo $_REQUEST['pwd'];
//echo $uname;
//echo $pwd;
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_found=mysql_select_db("sn", $con);
//$result = mysql_query("SELECT fname,password FROM udata");
if ($db_found)
{
$result = mysql_query("SELECT fname,password FROM udata");
while ( $db_field = mysql_fetch_assoc($result) )
{
if ($db_field['uname']==$uname && $db_field['password']==$pwd)
header( 'Location: www.youtube.com' ) ;
/*print $db_field['fname'] . "<BR>";
print $db_field['lname'] . "<BR>";
print $db_field['uname'] . "<BR>";
print $db_field['password'] . "<BR>";
*/
}
mysql_close($con);
}
else
{
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
</body>
</html>
请帮我解决一下这个。