Page 1 of 1

Problem Creating Login Script

Posted: Sun Feb 16, 2003 4:13 am
by Elise
I run this srcipt but I just get a not validnot valid error, when I have created the username and pass for myself on the database... what is wrong? could you please give me a hand with this.

Code: Select all

<html>
<head>
<title>validate.php</title>
</head>
<body>
<?php
	$user_name = $_POST&#1111;'user_name'];
	$password = $_POST&#1111;'password'];
	$db_user = 'mysql_user';
	$db_pass = 'mysql_pass';
	$user_name = $_POST&#1111;'user_name'];
	$password = $_POST&#1111;'password'];

	//connect to the DB and select the "dictator" database
	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('triple', $connection) or die(mysql_error());

	//set up the query
	$query = "SELECT * FROM users 
			WHERE user_name='$user_name' AND password='$password'";
			
	//run the query and get the number of affected rows
	$result = mysql_query($query, $connection) or die('error making query');
	$affected_rows = mysql_num_rows($result);

	//if there's exactly one result, the user is validated. Otherwise, he's invalid
	if($affected_rows == 1) &#123;
		print 'validated';
	&#125;
	else &#123;
		print 'not valid';
	&#125;
	//...snip...
	if($affected_rows == 1) &#123;
		print 'validated';
		//add the user to our session variables
		$_SESSION&#1111;'username'] = $user_name;
	&#125;
	else &#123;
		print 'not valid';
	&#125;
?>
</body>
</html>
Thanks alot![/b]

Posted: Sun Feb 16, 2003 7:56 am
by Jaymz

Code: Select all

$user_name = $_POST&#1111;'user_name']; 
   $password = $_POST&#1111;'password']; 
   $db_user = 'mysql_user'; 
   $db_pass = 'mysql_pass'; 
   $user_name = $_POST&#1111;'user_name']; 
   $password = $_POST&#1111;'password'];
Why do U write $user_name for 2 times? ))


First not valid - You have wrong query params and/or mysql returns 0 rows
Second one - the same as the first.

You better leave this block of code

Code: Select all

if($affected_rows == 1) 
   &#123; 
      print 'validated'; 
      $_SESSION&#1111;'username'] = $user_name; 
   &#125; 
   else 
   &#123; 
      print 'not valid'; 
   &#125;
and remove first block .

and if U have wrong username or pass U'll get only 1 error

Posted: Sun Feb 16, 2003 7:58 am
by Jaymz
aslo

I think Your host doesn't support construction $_POST, try to use $HTTP_POST_VARS

Posted: Mon Feb 17, 2003 2:07 am
by twigletmac
I think Your host doesn't support construction $_POST, try to use $HTTP_POST_VARS
Which version of PHP are you using?

Use phpversion() to find out.

Mac

ok

Posted: Mon Feb 17, 2003 2:18 am
by Elise
Current PHP version: 4.0.6

is the version I am using and I will just test the first sudgestions now =)
thanks!

Posted: Mon Feb 17, 2003 2:21 am
by twigletmac
Then as Jaymz suggested you cannot use $_POST as it is only available for PHP version 4.1 and up. You should have more luck with $HTTP_POST_VARS.

For more info:
http://www.php.net/manual/en/reserved.v ... ables.post

Mac

confused

Posted: Mon Feb 17, 2003 2:22 am
by Elise
which parts should I take out? which block are you talking about

d/w

Posted: Mon Feb 17, 2003 2:26 am
by Elise
I finally got 2 validated things =) thanks everyone, now can you sudgest a tutorial to show how to use sessions and how to now move onto a new page, the homepage.

Posted: Mon Feb 17, 2003 2:27 am
by twigletmac
You are going to have to rewrite the whole script. You need to replace $_POST with $HTTP_POST_VARS and are going to have to do your sessions differently too. You need to use the session_register() function and cannot use $_SESSION.

If you can try and get a newer version of PHP.

Mac

hmm

Posted: Mon Feb 17, 2003 2:34 am
by Elise
I downloaded a ready configured pack because I could not work out how to compile it with mySQL seperatley.... but now I am just getting confused because it will work on my localhost but not the website