PHP Help!

Soldato
Joined
14 Apr 2003
Posts
4,950
Location
Deepest Yorkshire
I'm a PHP noob and i'm trying to make a login script for my site, I just added some session stuff in but its not working...

Heres my code:

Code:
 1 <?
 2 include("dbinfo.inc.php");
 3 
 4 $email=$_POST['loginemail'];
 5 $password=$_POST['loginpassword'];
 6 
 7 mysql_connect($dbhost,$dbusername,$dbpassword);
 8 @mysql_select_db($dbdatabase) or die( "Unable to select database");
 9 
10 $query = "SELECT * FROM users WHERE email='$email' AND password='$password'";
11 $result = mysql_query($query);
12 
13 if (mysql_numrows($result) == 1) {
14 	$loggedinuser = mysql_result($result,0,"id");
15 	$userfirst = mysql_result($result,0,"first");
16 	$userlast = mysql_result($result,0,"last");
17 	$useremail = mysql_result($result,0,"email");
18 	echo("Hi, $userfirst");
19 	
20 	// create a new session
21 	session_start();
22 
23 	$_SESSION['uid']=$loggedinuser;
24 	$_SESSION['ufirst']=$userfirst;
25 	$_SESSION['ulast']=$userlast;
26 	$_SESSION['uemail']=$useremail;
27 }
28 else {
29 	echo('error');
30 	}
31 	
32 mysql_close();
33 ?>

and this is the error:

Code:
Hi, Andrew
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/xampp/xamppfiles/htdocs/calproject/login.php:18) in /Applications/xampp/xamppfiles/htdocs/calproject/login.php on line 21

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/xampp/xamppfiles/htdocs/calproject/login.php:18) in /Applications/xampp/xamppfiles/htdocs/calproject/login.php on line 21

Any help greatly appreciated!
 
cheers for that!, that bit works now, its just this bit now, for users to change password...


Code:
Code:
 1 <?
 2 include("dbinfo.inc.php");
 3 
 4 $old=$_POST['oldpassword'];
 5 $new1=$_POST['newpassword1'];
 6 $new2=$_POST['newpassword2'];
 7 $uid = $_COOKIE["uid"];
 8 
 9 if ($new1 == $new2 && strlen($new2) > 5) {
10 	mysql_connect($dbhost,$dbusername,$dbpassword);
11 	@mysql_select_db($dbdatabase) or die( "Unable to select database");
12 	
13 	$query = "SELECT * FROM users WHERE uid='$uid' AND password='$old'";
14 	$result = mysql_query($query);
15 	if (mysql_numrows($result) == 1) {
16 		$query = "UPDATE users SET password = '$newpassword1' WHERE id ='$uid'";
17 		if (mysql_query($query)) {
18 			echo('Successful');
19 		}
20 	}
21 	else echo('Old Password Incorrect');
22 	
23 	}
24 	else echo('New Passwords do not match or not longer than 5 chars');
25 
26 ?>


Error:
Code:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /Applications/xampp/xamppfiles/htdocs/calproject/changepassword.php on line 15
Old Password Incorrect
 
Back
Top Bottom