Page 1 of 1

SQL with PHP User login help

Posted: Thu Oct 31, 2002 2:40 pm
by austin0369
Right now, I have a login script...however I want a couple of things to show up when they login in. For example id like there email. Below you can see it as $email (i dont know what type of coding it needs to equal i was just playing around with it). When the user logs in i want the code to grab there e-mail. Do i need to put in the $query some code that makes it also grab the email? Dont know, first time using it, help would u be great

Code: Select all

<?php
	$db_user = 'mbnextime';
	$db_pass = 'hehehe';
	$username = $_POST&#1111;'username'];
	$password = $_POST&#1111;'password'];
	$email = $_POST&#1111;'email'];
	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('client', $connection) or die(mysql_error());
	$query = "SELECT * FROM users 
			WHERE username='$username' AND password='$password'";
	$result = mysql_query($query, $connection) or die('error making query');
	$affected_rows = mysql_num_rows($result);
	if($affected_rows == 1)
	&#123;
    		include("test.php");
	&#125;
?>

Posted: Thu Oct 31, 2002 3:24 pm
by volka

Code: Select all

SELECT * FROM users
includes all fields of table users to the resultset. If you're sure about the needed fields you can limit it to only those, e.g. you're only interested in the fields email and id you can perform

Code: Select all

SELECT email,id FROM users
.
Take a look at
http://www.php.net/manual/en/function.m ... ch-row.php ,
http://www.php.net/manual/en/function.m ... -assoc.php and
http://www.php.net/manual/en/function.m ... -array.php

Posted: Thu Oct 31, 2002 3:53 pm
by austin0369
Doesnt work,

What they do is insert a USERNAME and PASSWORD (http://www.beyond-reason.net/t), and when they log in I want it to display information from the database (ie. e-mail, name, etc) WHen I do what u told me 2 do, all I get is "Invalid Username/Password"

Posted: Thu Oct 31, 2002 4:44 pm
by austin0369
go to http://www.beyond-reason.net/t First box type illusiondev 2nd box type test. Press login. There you see it says "welcome illusiondev, to your contorl panel. You remail is (then a blank). I want there email to show up there. Now how do i edit the PHP code so that the EMAIL will show up there?>!

echo

Posted: Thu Oct 31, 2002 5:39 pm
by phpScott
because you are including test.php and I don't know what you are doing to blank out the screen and start agian but you should just be able to echo out the value in email like so:
echo $row[email];
where ever you want it.
by including the test.php file it has access to all the variables in the page that included it.
Or you might want to do some thing like

if($affected_rows == 1)
{
$email = $row[email];
include("test.php");
}

try these suggestions and if they don't work post your test.php file.

phpScott

Posted: Thu Oct 31, 2002 5:49 pm
by austin0369
Heres my login.php:

Code: Select all

<html>
<head>
<title>LogIn</title>
</head>
<body>
<?php
	$db_user = 'austin';
	$db_pass = '220221';
	$username = $_POST&#1111;'username'];
	$password = $_POST&#1111;'password'];
	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('client', $connection) or die(mysql_error());
	$query = "SELECT * FROM users
		WHERE username='$username' AND password='$password'";
	$result = mysql_query($query, $connection) or die('error making query');
	$affected_rows = mysql_num_rows($result);
	if($affected_rows == 1)
	&#123;
		$email = $row&#1111;email]; 
    		include("test.php");
	&#125;
?>
</body>
</html>
And that didnt work...

Here is my test.php

Code: Select all

<html>
<head>
<title>
</title>
</head>
<body>
<?
$email = $row&#1111;email]; 
	echo("Welcome $username to your control panel. Your email is $email.");
?>
Im so confused :(

Posted: Thu Oct 31, 2002 5:56 pm
by volka

Posted: Thu Oct 31, 2002 6:10 pm
by austin0369
See the problem with that stuff, is that more then half of it is like foreign to me. It makes no sense. Thats why im always looking for help or tutorials that actually make it clear

Posted: Thu Oct 31, 2002 6:40 pm
by austin0369
Do you knwo were I can view a better writing on those?

Posted: Thu Oct 31, 2002 9:34 pm
by phpScott
sorry try this

Code: Select all

if($affected_rows == 1)
&#123;
   $row = mysql_fetch_array($result);    
   $email = $row&#1111;email];
   include("test.php");
&#125;
and then in your test.php just

Code: Select all

<?
   echo("Welcome $username to your control panel. Your email is $email.");
?>
of course if you could get your $usename then you should be able to get $email

Posted: Fri Nov 01, 2002 5:31 am
by austin0369
Scott....

I LOVE YOU :oops:

Im still trying to learn PHP so im new and its making me really mad and stuff, and I thank you for making my day ;). Also thanks for the others for the help. Im going out today to get some books, hopefully I can learn more with those, maybe get some classes to. Once again, thanks scott.

-Austin