[英]MySQL query Working fine on localhost but not on server
My query is working absolutely fine on localhost but when i execute this on server the query successfully passed but it redirect myself to login.php and shows login query instead going on welcome.php page 我的查询在localhost上运行正常,但是当我在服务器上执行此查询时,查询成功通过,但是将自己重定向到login.php并显示登录查询,而不是在welcome.php页面上
suppose when i enter username/password it redirect myself to login.php with the successful MySQL syntax query.. and query shows on the screen 假设当我输入用户名/密码时,它将使用成功的MySQL语法查询将自己重定向到login.php。并且查询显示在屏幕上
like my username is v@v.com password v then after pressing login button it redirect me to login.php instead of welcome.php showing query like this query on the screen 像我的用户名是v@v.com密码v,然后按登录按钮后,它将我重定向到login.php而不是welcome.php在屏幕上显示类似此查询的查询
SELECT * FROM members WHERE username = 'v@v.com' AND pas = '7a38d8cbd20d9932ba948efaa364bb62651d5ad4'
this is my code "login.php" 这是我的代码“ login.php”
<?php
//Start session
session_start();
//Connect to mysql server
include('config.php');
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$a = clean($_POST['username']);
$password = clean($_POST['password1']);
$passwordx= sha1($password);
//Create query
$qry="SELECT * FROM members WHERE username = '$a' AND pas= '$passwordx'";
$result=mysql_query($qry);
echo $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_FIRST_NAME'] = $member['fname'];
$number=$member['number'];
if($number=='1')
{
mysql_query("UPDATE members SET number=number+1 WHERE id='".$_SESSION['SESS_MEMBER_ID'] ."' ") ;
header("location: info.php");
exit();
}
else
{
header("location: welcome.php");
exit();
}
exit();
} elseif(mysql_num_rows($result) == 0){
header("location: error.php");
exit();
}
} else {
header("location: error.php");
exit();
}
?>
can someone spot the mistake? 有人可以发现错误吗?
This: echo $qry;
这个: echo $qry;
Once you do that, you cannot redirect using header()
. 一旦这样做,就无法使用header()
重定向。
From the documentation ( http://php.net/manual/en/function.header.php ): 从文档( http://php.net/manual/zh/function.header.php ):
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. 请记住,必须先通过常规HTML标记,文件中的空白行或从PHP发送任何实际输出,然后调用header()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.