Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Set up credentials
- $servername = "localhost";
- $username = "root";
- $password = "";
- $database = "users";
- // Create connection
- $link = mysqli_connect($servername, $username, $password, $database);
- // Check connection
- if (!$link) {
- die("Connection failed: " . mysqli_connect_error());
- }
- //Start query
- $username = $_POST['username'];
- $password = $_POST['password'];
- $sql = "SELECT * FROM userdata WHERE username='$username'";
- $result = $link->query($sql);
- //Count number of row with that username
- $count=mysql_num_rows($result);
- //if only one match then...
- if($count==1){
- $row = mysql_fetch_assoc($result);
- if(crypt($password,$row['password']) == $row['password']){
- session_register("username");
- session_register("password");
- echo "Login Successful";
- return true;
- }
- else {echo "Wrong username or password";
- return false;
- }
- }
- else {
- echo "Wrong username or password";
- return false;
- }
- if ($link->query($sql) === TRUE) {
- echo "","<br>";
- } else {
- echo "Error updating record: " . $link->error;
- }
- $result->close();
- $link->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement