简体   繁体   中英

Getting data from mysql and comparing it

i am really new in PHP and MYSQL. I made a page where user can sign up and another where user can sign in. I tryed get user from database and compare it with what he submit, but it doesnt work.

if(!empty($_POST['Username']) && !empty($_POST['Password'])){
$sql = "SELECT * Usernames FROM users";
$result = mysql_query($sql);
if ($result) {
    while($row = mysql_fetch_array($result)) {
             $_POST['Username'] = $row["Usernames"];
            echo 'Hello';
    }
        }else{
            echo 'Wrong username or password';
            }
}else{
    echo 'Please insert username and password!'; 
    }

Try:

    $user = $_POST['Username'];
    $pw = $_POST['Password'];
    if(!empty($user) && !empty($pw){
       $sql = "SELECT * FROM users where username = $user and password = $pw";
         $result = mysql_query($sql);
         if ($result) {
           echo 'Hello';
    }
    }else{
                echo 'Wrong username or password';
            }
    }else{
  echo 'Please insert username and password!';
 }

Don't use MySQL...it's too old....use MySQLi or PDO and always use real_escape_string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM