Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 管理员登录无法正常工作_Php_Mysql - Fatal编程技术网

Php 管理员登录无法正常工作

Php 管理员登录无法正常工作,php,mysql,Php,Mysql,所以我有一个问题的“管理员登录”,我一直试图使工作。如果你们能看看我的代码,看看发生了什么,这将是非常有帮助的。所有名称都与mysql中的名称匹配。错误不断出现,说我没有正确的用户名/密码。。。但我知道 <?php if (isset($_POST['login'])){ $con = mysql_connect("localhost", "dxhxxx", "tcqxxx"); if (!$con){ die("Cannot connect:" . mysql_error()

所以我有一个问题的“管理员登录”,我一直试图使工作。如果你们能看看我的代码,看看发生了什么,这将是非常有帮助的。所有名称都与mysql中的名称匹配。错误不断出现,说我没有正确的用户名/密码。。。但我知道

<?php

if (isset($_POST['login'])){    

$con = mysql_connect("localhost", "dxhxxx", "tcqxxx");
if (!$con){
die("Cannot connect:" . mysql_error()); 
}

mysql_select_db("dxh6110",$con);

$userName = $_POST['username'];
$passWord = $_POST['password'];

$sql = "select * from Churchadmin where username='$userName' AND      password='$passWord'";
mysql_query($sql,$con);

if(mysqli_num_rows($run)>0){

    $_SESSION['username']=$userName;
    $_SESSION['password']=$passWord;
    //if all information is good you will go to the next page
    echo "<script>window.open('view_prayers.php','_self')</script>";

    }
    //if password or username is wrong this will give them an alert
    else{
    echo "<script>alert('Admin details are incorrect!')</script>";
    }

}

mysql_close($con);

?>

首先,您将MySQL库与
mysqli\u num\u行混用
use
MySQL\u num\u行

  • 这些不同的MySQL函数不会相互混合
如果尚未启动会话,则还需要启动会话

还要确保表单元素包含名称属性

例如:

那么这一行:

mysql_query($sql,$con);

if(mysqli_num_rows($run)>0){
这应该理解为

$run = mysql_query($sql,$con);

if(mysql_num_rows($run)>0){
  • 没有为其定义
    $run
    变量

  • 错误报告将引发未定义的变量运行。。。注意

你也可以改变

$run = mysql_query($sql,$con);

  • 以查看您的查询是否失败

我注意到您可能正在以明文形式存储密码。如果是这样的话,我们非常不鼓励这样做

我建议您使用或PHP5.5的函数。对于小于5.5的PHP,请使用

另外,在SQL注入方面,它们更安全

添加到文件的顶部,这将有助于查找错误

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

好的,我将对sql/sqli进行这些更改。名称属性是正确的,我正要编辑我的帖子来输入我的表单。哦,而且完全忘了启动会话。@DLH我做了一些编辑。您可能需要重新加载我的答案。@DLH不客气。我给你的链接中有很多例子,网络上有很多;-)那么,问题解决了吗?编辑:你删除了你的评论。我从来都不太了解SQL注入及其功能,甚至不太了解它的外观。但我相信我可以做一些研究并查找它。我需要将sqli更改为sql吗?比如:if(mysqli_num_rows($run)>0)到if(mysql_num_rows($run)>0)?@DLH正如我在回答中所概述的,是
if(mysql_num_rows($run)>0)
而不是
if(mysqli_num rows($run)>0)
-
mysqli
mysql
函数不会混合在一起。再看一遍我的答案,然后重新加载页面。
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code