我正在使用php,javascript制作测试登录页面。但是,我无法在php中获得select查询的结果。我的代码出了什么问题?
感谢您的帮助。
(apache2 - error.log)
[Mon Jan 15 17:22:55.208889 2018] [php7:notice] [pid 12752:tid 1396] [client :: 1:54512] mysqli_result :: __ set_state(array(\ n'current_field') => NULL,\ n'field_count'=> NULL,\ n'length'=> NULL,\ n'num_rows'=> NULL,\ n'type'=> NULL,\ n))的, 引用者:http://localhost/sharepractice/index.php?id=signin
(signin.js)
var save = document.getElementById('btnSignIn');
btnSignIn.addEventListener('click', function() {
if ($('#inputEmail').val() == '' ||
$('#inputPassword').val() == '' ) {
alert("check input.");
window.location.search = "?id=signin";
}
else {
$.ajax({
type: 'POST',
dataType: 'json',
async: false,
url: './signin.php',
data: {
email: $('#inputEmail').val(),
password: $('#inputPassword').val()
},
success: function (data) {
console.log(data);
window.location.href = "index.php"
},
error: function (request, status, error) {
console.log(error);
window.location.search = "?id=signin";
}
});
}
});
(signin.php)
<?php
$mysql_hostname = "localhost";
$mysql_user = "spman";
$mysql_password = "spman";
$mysql_database = "sharepractice";
$conn = mysqli_connect($mysql_hostname,$mysql_user, $mysql_password);
mysqli_select_db($conn, $mysql_database);
$query = "select email, nickname from userinfo where vald = 'Y' and email = '".$_POST['email']."' and password = '".$_POST['password']."'";
$result = mysqli_query($conn, $query);
error_log(var_export($result, 1));
$count = mysqli_num_rows($result);
error_log(var_export($count, 1));
if ($count == 1) {
$row = mysql_fetch_row($return);
error_log(var_export($row, 1));
session_start();
$_SESSION['email'] = $row[0];
$_SESSION['nickname'] = $row[1];
$return = array ('result'=>true, 'message'=>"success");
echo json_encode($return);
}
else {
$return = array ('result'=>false, 'message'=>"fail");
echo json_encode($return);
}
mysqli_close($conn);
?>