Jump to content

Login Warning


nepzap2

Recommended Posts

Hello Everyone,

 

I'm creating a login application that is not working properly. There are two Problems,

 

1. Is that the login form is not checking the database for the correct match; so you can log in as anything,

2. I keep getting a warning that reads the following:

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in   

    C:\web\htdocs\addMySQL\login\section7sol\header.php on line 29"

 

line 29 is this one:

if($row = mysql_fetch_array($result)) {

 

my database schema is the following:

table = login and there are two fields (user_name, user_password)

 

Any help is gratly appreciated!

 

Thank you

 


<?php
session_start();
if(!isset($_SESSION['username'])){
	session_register("username");
}



//connect to the database
mysql_connect("localhost", "root", "*****") or die(mysql_error());
@mysql_select_db("users") or die(mysql_error());

//process the login form
if(isset($_POST['login']) && isset($_POST['username'])){
	$username = $_POST['username'];
	$password = hash('sha256',$_POST['userpass']);

	//this assumes that you have a table in your database with schema:
	//users(username: VARCHAR(50), password: VARCHAR(64))
	//where the password column is the sha256 hash of the user passwords.
	//Note that phpMyAdmin doesn't support sha256 hashing from their interface, but you can do it by issuing
	//an INSERT statement from a PHP file.

	$query = "SELECT FROM login WHERE user_name='".$username."' user_password ='".$password."'";


	$result = mysql_query($query);

	if($row = mysql_fetch_array($result)){
    	if($password == $row['user_password']){
			$_SESSION['username'] = $username;
		}
	}	
}

//process logging out
if(isset($_GET['logout'])){
	unset($_SESSION['username']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
      <title>Login</title>
   </head>
   <body>

<?php
//TODO
if(isset($_SESSION["username"])){
	echo "<p>Hello, " . $_SESSION['username'] . ".  Would you like to <a href=\"" . $_SERVER['PHP_SELF'] . "?logout\">logout</a></p>";
}
//END TODO
?>

Link to comment
https://forums.phpfreaks.com/topic/97148-login-warning/
Share on other sites

dude clown i love this

 

<?php echo "The n00b is back"; ?>

 

I don't test my codes before I post them.

 

thats great

 

hehe well thanks i guess even tho i sense some sort of sarcasm in there? :)

 

i'm not here to write a fully working code for someone.. i'm here to guide them and learn more.. the day you dont consider urself a noob you say "i have nothing more to learn" and get stuck there for the rest of your life

Link to comment
https://forums.phpfreaks.com/topic/97148-login-warning/#findComment-497233
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.