douxu0550 2015-10-20 11:07
浏览 38

MySQL无法执行

Im new to programming and I'm trying to create a login form using php/mysql and I have faced some problems. I cannot understand why my sql code cannot being executed, Im using localhost. Could you guys help me? Thanks Here is the code that i wrote

<?php

$host = "localhost";
$user = "root";
$pass = "";
$db = "login";

mysql_connect($host, $user, $pass);
mysql_select_db($db);


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

    $sql = "SELECT * FROM users WHERE username'".$username."' AND password='".$password."' LIMIT 1";
    $res = mysql_query($sql);
    if (mysql_num_rows($res) == 1){
        echo "You have successfully logged in.";
        exit();
    }else{
        echo "Invalid password information.";
        exit();
    }
}
?>
  • 写回答

2条回答 默认 最新

  • dongmei9961 2015-10-20 11:07
    关注

    I think you forgot =

     $sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
    
    评论

报告相同问题?