0

我的 db_field 有什么问题。在第 15 行:

$sql = "SELECT * FROM Persons WHERE $loFmUname = '".strtolower($db_field['UserName'])."' AND $myPwd = '".$db_field['UserPwd']."'";

我的代码是

<?php
session_start();
$con = mysql_connect("localhost","root","");
if (!$con){
   die('Could not connect: ' . mysql_error());
}

$db_exist = mysql_select_db("seta", $con);

$myUName = $_POST["username"];
$myPwd = $_POST["pwd"];
$loFmUname = strtolower($myUName);

if($db_exist){
    $sql = "SELECT * FROM Persons WHERE $loFmUname = '".strtolower($db_field['UserName'])."' AND $myPwd = '".$db_field['UserPwd']."'";
    $result = mysql_query($sql);
    if($result){
        $_SESSION['loged'] = '$loFmUname';
        header('Location: index.html');
        die();
    } else {
        echo "Invalid username and/or password please";
        echo "<a href='login.php'>try again</a>";
    }
} else {
    echo "Sorry Database Not Found";
}

mysql_close($con);
?>
4

2 回答 2

0

简单:变量db_field不会在任何地方用任何值初始化。你不是在使用它之前创建它。

于 2012-05-15T08:41:11.180 回答
-1

尝试这个

$sql = "SELECT * FROM Persons WHERE ". $loFmUname." = '".strtolower($db_field['UserName'])."' AND ".$myPwd." = '".$db_field['UserPwd']."'";
于 2012-05-15T08:41:54.037 回答