此登录过程在我的localhost中工作正常,但是当我在主机上传它并尝试在实时服务器上测试它失败了! 我将我的数据库上传到服务器并尝试使用注册用户登录,但是当我提交表单时没有任何反应! 我使用ajax并警告从服务器返回的数据,它只是提醒一条空白消息,没有错误,没有警告,没有数据回显!
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$id;
$status = 1;
require_once("../scripts/config.php");
$stmt = $con->stmt_init();
if ($stmt = $con->prepare("SELECT COUNT(email) AS counte FROM users WHERE email=?"))
{
$stmt->bind_param("s", $username);
$stmt->execute();
$obj = $stmt->get_result()->fetch_object();
$counte = $obj->counte;
$stmt->close();
}
if($counte == 1) // email mojud ast
{
if ($stmt = $con->prepare("SELECT COUNT(*) AS countr, id, fname, lname, img FROM users LEFT JOIN userd ON users.id = userd.userid WHERE email=? AND password=?"))
{
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$obj = $stmt->get_result()->fetch_object();
$countr = $obj->countr;
$id = $obj->id;
$fname = $obj->fname;
$lname = $obj->lname;
$img = $obj->img;
$stmt->close();
if($countr == 0)
{
echo "incorrect";
}
else if($countr == 1)
{
session_start();
$_SESSION['userid'] = $id;
echo $img."*".$fname." ".$lname."*".$id."*";
}
}
}
else if($counte == 0)
{
echo "notexist";
}
mysqli_close($con);
?>
答案 0 :(得分:0)
而不是
if($counte == 1) // email mojud ast
{
}
试试这个
if($counte > 0)
{
}
这是我在登录模块上使用的内容 如果你想考虑在这里使用PDO,我的代码可以随意使用它作为参考
$con = new PDO("mysql:host=". DB_host .";dbname=db", DB_username , DB_password);
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//checking if valid
$sql="SELECT * FROM users WHERE username=:var1 AND password=:var2 ";
$stmt=$con2->prepare($sql);
$stmt->bindParam(':var1',$var1, PDO::PARAM_STR);
$stmt->bindParam(':var2',$var2, PDO::PARAM_STR);
$stmt->execute();
if($stmt->rowCount() > 0 ){
}