[英]php/mysql help needed no error being outputed
can some assist me with my code, everything looks correct checked each line at least 10 times. 可以为我的代码提供帮助吗,检查每行至少十次,看起来一切正确。 I've even hardcode in the user/pass for the query and still nothing. 我什至在用户/通行证中为查询添加了硬编码,但还是一无所获。
<?php
include "database.php";
$sql = "SELECT UserName, Password, Language, Editor FROM admin_login WHERE UserName='".$_POST['username']."' AND Password='".$_POST['pwd']."'";
$result = @mysql_query($sql);
$line = @mysql_fetch_assoc($result);
if (mysql_num_rows($result) == 0) {
#unsuccessful login
header('Location: index.php' );
} else {
#login successful, setting up session
ob_clean();
session_start();
$_SESSION['user'] = $line['UserName'];
$_SESSION['pass'] = $line['Password'];
$_SESSION['lang'] = $line['Language'];
$_SESSION['editor'] = $line['Editor'];
#send to editor page
if ($_SESSION['lang'] == 'List') {
header('Location: list.php');
exit;
#send to announcer page
} else if ($_SESSION['lang'] == 'Order') {
header('Location: order.php');
exit;
}
}
?>
从函数mysql_query和mysql_fetch_assoc中删除@,您将显示错误。
Some steps to follow: 请遵循以下步骤:
Add MySQL error reporting such as (to the end of your SQL statement): 添加MySQL错误报告,例如(到SQL语句的末尾):
or die ("Query failed: " . mysql_error() . " Actual query: " . $query) 或死亡(“查询失败:”。mysql_error()。“实际查询:”。$ query)
Remove the @ symbols -- these suppress errors. 删除@符号-这些可以消除错误。
Here's my version: 这是我的版本:
<?php
include 'database.php';
$sql = "SELECT `UserName`, `Password`, `Language`, `Editor` FROM `admin_login` WHERE `UserName` = '" . mysql_real_escape_string($_POST['username']) . "' AND `Password` = '" . mysql_real_escape_string($_POST['pwd']) . "' LIMIT 1;";
$result = mysql_query($sql);
if ($result === false)
{
// Unsuccessful Login
header('Location: index.php');
}
$user = mysql_fetch_assoc($result);
$_SESSION['user'] = $user;
if ($user['Language'] == 'List')
{
header('Location: list.php');
exit;
}
elseif ($user['Language'] == 'Order')
{
header('Location: order.php');
exit;
}
?>
If it still shows some errors copy/paste them here, if no errors are displayed and code still don't works then show us your database scheme and a database.php
file. 如果仍然显示一些错误,请在此处复制/粘贴它们,如果未显示任何错误并且代码仍然不起作用,请向我们显示您的数据库方案和一个database.php
文件。
As already stated, remove all the @
prefixes from functions. 如前所述,从函数中删除所有@
前缀。 That suppresses all the errors. 这样可以消除所有错误。
Additionally, add the following two lines to the start of your script: 此外,将以下两行添加到脚本的开头:
error_reporting(E_ALL);
ini_set('display_errors','1');
Your error report of PHP may be set to off. 您的PHP错误报告可能已关闭。 Please make it on or otherwise put ini_set('display_errors','1');
请放在上面或以其他方式放入ini_set('display_errors','1');
in the top of the php page where you are having this problem. 在您遇到此问题的php页面顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.