doufang2023 2013-01-25 21:57
浏览 19

PHP代码不起作用。 简单的代码,但我被困[关闭]

My PHP code gives an error. My idea was to just check if the username and password exists in the database and then redirect it to the URL.

enter code hereI have two pages created. One is index and other is redirect. Redirect code is giving problem.

<!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>

Please help me with this.

  • 写回答

3条回答 默认 最新

  • dongtan2603 2013-01-25 22:02
    关注

    I think you have to change this:

    if ($db_field['uname']==$uname && $db_field['password']==$pwd)
    

    to this:

    if ($db_field['fname']==$uname && $db_field['password']==$pwd)
    
    评论

报告相同问题?