duanbi2760 2017-01-25 03:12
浏览 72
已采纳

登录错误并登录优化[重复]

This question already has an answer here:

Hey guys I have been working on a social networking site and have been working on the login and registration systems. I am pretty new to php so my code may not be the best. The issue I am having right now is my login. This is my log in form on my index.php page.

<form name="loginform" method="post" action="includes/login.php" >
  <table>

  <input type="submit" id="submitbox" name="login" value="Submit">

  <input type="password" name="password" id="passwordbox" required="true" placeholder="Password">

  <input type="text" name="username" id="usernamebox" required="true" placeholder="Username">

  </table>

</form>

I send the form to my login.php page (includes folder) and process the information and if successful start the session and redirect the user to the home.php page. When I click submit to log me in I am brought to an error saying:

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /Applications/XAMPP/xamppfiles/htdocs/VolleypagesFixed/includes/login.php on line 14

Warning: mysqli_error() expects parameter 1 to be mysqli, resource given in /Applications/XAMPP/xamppfiles/htdocs/VolleypagesFixed/includes/login.php on line 14

This line is on my log in page and this is the code for that page:

<?php
// start the session
session_start();

require_once ('connect.php');

// if form is submitted

if(isset($_POST['username']) and isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM `users` WHERE username='$username' and password='$password'";

line 14 - $result = mysqli_query($con, $query) or die(mysqli_error($con));
$count = mysqli_num_rows($result);

// create session if values are equal
if($count == 1) {
    // cookie is set
   if(isset($_COOKIE['ID'])) {
            $id = mysql_real_escape_string($_COOKIE['ID']);
        }
        if(!isset($id)){
            die("Cookie not found");
        }
} else {
    echo "Invalid Login";
    header("Location: http://localhost/FolderName/index.php");
}
}

// if user is logged in redirect
if(isset($_COOKIE['ID'])) {
header("Location: http://localhost/FolderName/home.php");
}

?>

Any help on the error on line 14 or any advice and how I have set my login up would be very helpful!

</div>
  • 写回答

2条回答 默认 最新

  • douxin1884 2017-01-25 03:24
    关注

    Try this

    Use

     mysqli_connect('localhost', 'root', 'root', 'test');
    

    Instead:

      mysql_connect
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能