PDA

View Full Version : Help Please with a login problem


MJS
04-04-2007, 12:51 PM
I have worked though DavidJ's excellent videos and have a problem with the login. On the login page I can put in the User id and the Password and nothing happens it just stays on the login page. If I put in the incorrect Name and password it takes me to the login fail page below is the PHP script.


<?php
require_once("Connections/connection.php"); ////database connection
session_start();
/////////////////////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
///////////////////////////////////
if ($userid && $password){
///////////////////////////////////////////
$query = sprintf("SELECT * FROM users_id where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////
}
if ($rowAccount){
$_SESSION['id'] = $rowAccount['user_id'];
header("location: Member_Page.php");
exit;
}
elseif($submitted){
header("location: Login_fail.php");
exit;
}
?>

davidj
04-04-2007, 01:50 PM
this is incorrect...

if ($rowAccount){


this needs to be

if ($rowAccount > 0){

MJS
04-04-2007, 02:14 PM
Thanks for the quick reply, It now sends me to the failed lgoin page ???

davidj
04-04-2007, 02:39 PM
post ya form code

MJS
04-04-2007, 02:46 PM
<div align="center">
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']?>">
<table width="200" border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="64" scope="col">User ID </th>
<th width="122" scope="col"><input name="userid" type="text" id="userid" /></th>
</tr>
<tr>
<th scope="row">Password</th>
<td><input name="password" type="password" id="password" /></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td><input name="submitted" type="hidden" id="submitted" value="1" />
<input name="submitted" type="submit" id="submitted" value="Submit" /></td>
</tr>
</table>
</form>
</div>

Hope this is what you wanted

davidj
04-04-2007, 02:59 PM
the form seems fine

try this... where you have...


$query = sprintf("SELECT * FROM users_id where user_name = '$userid'


add an echo here...


echo $query = sprintf("SELECT * FROM users_id where user_name = '$userid'


then try to login

print the message when it appears in this thread

MJS
04-04-2007, 03:14 PM
SELECT * FROM users_id where user_name = 'G0TVD' and user_password = 'Martin'
Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\Web Root\South_West_Herts_RAYNET\Login.php:14) in C:\Inetpub\wwwroot\Web Root\South_West_Herts_RAYNET\Login.php on line 30


this is what happen when I login. This is line 30 of the login.php
header("location: Login_fail.php");

and this is line 14 login.php
echo $query = sprintf("SELECT * FROM users_id where user_name = '$userid' and user_password = '$password'");

davidj
04-04-2007, 03:19 PM
ok

remove that echo

all is well there

...

please check your database and make sure you are keyin the correct data into the form. Check your spelling and omit capitals

MJS
04-04-2007, 03:22 PM
OK David thanks will check all my spelling and other parts and will post what happens....

MJS
04-04-2007, 05:06 PM
I think I know what the problem is.. I can conncet to the database but it not looking in the right place or I am not sending it in the right direction so it not seeing the data I am putting in . It sends me to the fail page so it thinks I not there.

I have taken a screen grab of the data base so you can see if it could be that and can send it if you need it

davidj
04-04-2007, 07:04 PM
if there was a page that wsnt there you would get a 404 error

do this after the select statement and run it again


print_r($rowAccount);

MJS
04-05-2007, 09:36 AM
OK gave that a go and had the same result sent to the fail page...

davidj
04-05-2007, 09:42 AM
its very difficult trouble shooting a problem like this through this forum

all i can say is follow the tutorials again to the letter and get that example working. Once you have the tutorial example working then just change the script to suit your needs

try this first

where you have...

elseif($submitted){
header("location: Login_fail.php");
exit;
}
?>
add this mod...
elseif(!$rowAccount && $submitted){
header("location: Login_fail.php");
exit;
}
?>

MJS
04-05-2007, 10:37 AM
When I put the code in it give me a error on line 28.
OK David thanks for your help I will go back to the start and have to try again.
I am new to PHP codeing.

Martin