making a login screen to verify user

alright so im reading larry ullmans PHP beginner book ( which is great!) but all i want to do is a make a login screen to verify that a user in my database is who they say they are

would i use a IF $true conditional? and the data could be read at my database at some location and verify that the person is who they say they are? and if not make a simple Print

wrong username or password

Hi there,

The following code does what you want:

[php]<?php

if($_POST)
{
$db = new mysqli(HOSTNAME, USERNAME, PASSWORD, DATABASE);

 $user = $_POST['username'];
 $pass = $_POST['password']; // You can use sha1($_POST['password']) to encryt

 $result = $db->query("SELECT * FROM users WHERE user='$user' AND pass='$pass'");

 if($result->num_rows > 0)
 {
      echo 'SUCCESS';
 }
 else
 {
      echo 'FAILED';
 }

 die($db->close());

}

?>

Username:
Password:
[/php]

Take a look at the code above and see if you can dissect it and see what it’s doing. Also, if you don’t know, HOSTNAME USERNAME PASSWORD and DATABASE are placeholders for your MySQL database information.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service