Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PHP Login System Help Please

    Hello guys,

    I'm trying to make a login system linked to a mySQL database and below is what I have so far. The problem I'm having is when I try to submit both a username and password, I think the database query is failing and it leads to a blank page. Any ideas? Any help would be greatly appreciated.

    Thanks

    Here's the page I'm talking about: http://aerithea.com/login/login.php

    Code:
    <?php
    session_start();
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    		<title>Member System - Login</title>
    	</head>
    <body>
    
    <?php
    
    $form = "<form action='./login.php' method='post'>
    <table>
    <tr>
    	<td>Username:</td>
    	<td><input type='text' name='user' /></td>
    </tr>
    
    <tr>
    	<td>Password:</td>
    	<td><input type='password' name='password' /></td>
    </tr>
    
    <tr>
    	<td></td>
    	<td><input type='submit' name='loginbtn' value='Login' /></td>
    </tr>
    </table>
    </form>";
    
    	if ($_POST['loginbtn']) {
    		$user = $_POST['user'];
    		$password = $_POST['password'];
    
    		if ($user) {
    			if ($password) {
    				
    				require("connect.php");
    
    				$password = md5(md5("q`wkIa4".$password."qwe;lnm"));
    				//make sure login info correct
    				$query = msql_query("SELECT * FROM users WHERE username='$user'");
    				$numrows = mysql_num_rows($query);
    				if ($numrows == 1) {
    					$row = mysql_fetch_assoc($query);
    					$dbid = $row['id'];
    					$dbuser = $row['username'];
    					$dbpass = $row['password'];
    					$dbactive = $row['active'];
    
    					if($password == $dbpass) {
    						if($dbactive == 1) {
    
    							//set session info
    							$_SESSION['userid'] = $dbid;
    							$_SESSION['username'] = $dbuser;
    
    							echo "You have been logged in as <b>$dbuser</b>. <a href='./member.php'>Click here</a> to go to the member page.";
    
    						}
    						else
    							echo "You must activate your account to login. $form";
    					}
    					else
    						echo "You did not enter the correct password. $form";
    				}
    				else
    					echo "The username you entered was not found. $form";
    
    				mysql_close();
    
    			}
    			else
    				echo "You must enter your password. $form";
    		}
    		else
    			echo "You must enter your username. $form";
    
    	}
    	else
    		echo $form;
    
    
    
    ?>
    
    </body>
    </html>
    connect.php is this:
    Code:
    <?php
    
    mysql_connect("localhost", "/*database name*/", "/*database password*/");
    mysql_select_db("/*table name*/");
    
    ?>

  • #2
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found the issue. I was missing a y in my $query.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •