我已经尝试搞清楚错误很长一段时间了。即使尝试使用尝试和捕获但无济于事。我得到的输出是“查询失败”(这是其他部分)。代码也可以在不同的机器上运行。任何人都可以帮我解决这个问题吗?
<?php
session_start();
//Include database connection details
require_once('connect.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
try {
//Sanitize the POST values
$username = clean($_POST['username']);
$phone = clean($_POST['phone']);
/*$username = 'Ajay M';
$phone = '9810827804';*/
//Input Validations
if($username == '') {
$errmsg_arr[] = 'Username missing';
$errflag = true;
}
if($phone == '') {
$errmsg_arr[] = 'phone missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: log.php");
exit();
}
//Create query
$qry="SELECT * FROM app_user WHERE name='$username' AND phone='$phone'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_NAME'] = $member['username'];
$_SESSION['SESS_PHONE'] = $member['phone'];
session_write_close();
header("location: suzuki_home.php");
exit();
}else {
//Login failed
$errmsg_arr[] = 'user name and phone not found';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: fail.php");
exit();
}
}
}else {
die("Query failed");
}
}
catch (Exception $e) {
echo ($e->getMessage());
}
?>
答案 0 :(得分:1)
name
是MySQL
上的保留字。因此,请在查询中使用反引号括起列名。
$qry="SELECT * FROM `app_user` WHERE `name`='$username' AND `phone`='$phone'";
答案 1 :(得分:-1)
必须在.ini文件中设置错误报告,但您也可以在.php文件中执行此操作:
ini_set("display_errors", true);
error_reporting(E_ALL);