Page 1 of 1

LoigIn Issue

Posted: Thu Jan 12, 2012 9:21 am
by jayson.ph
Hi all, any buddy could help.

i have index.php, login.php, connection.php and welcome.php that i can't find where is the error between of them. and all of this is for login issue that i want to login but suddenly i can't login that i want to show the words WELCOME please take a look a code below.


index

Code: Select all

<html>
<body>
<table border = "0" bgcolor = "#ffffff" cellpadding = "2" cellspacing = "3" align = "center">
<form action="login.php" method="post">
<tr>
	<td>Firstname: </td> 
		<td><input type="text" name="uname" /></td>
</tr>
<tr>
	<td>Lastname: </td>
		<td><input type="text" name="pwd" /></td>
</tr>
<tr>
	<td colspan = "2" align = "center"><input type="submit" /></td></tr>
</form></table>
</body>
</html> 

login

Code: Select all

<?php

	include("connection.php");
	
	
mysql_select_db("mydatabase");
	$uname = $_POST['uname'];
	$pwd = $_POST['pwd'];
	$uname = stripslashes($uname);
	$pwd = stripslashes($pwd);
	$uname = mysql_real_escape_string($uname);
	$pwd = mysql_real_escape_string($pwd);
		$sql = SELECT * FROM $tbl_login WHERE uname = '$uname', and pwd = '$pwd';
			$result = mysql_query($sql);
			$count = mysql_num_rows($result());
		if($count == 1)
		{
			session_register("uname");
			session_register("pwd");
				header("location: welcome.php");
		}
		else
			echo "Please login again";

?> 
connection

Code: Select all

<?php
$con = mysql_connect("localhost","root","jayson");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

            
?>
welcome

Code: Select all

<?php
	session_start();
		if(!session_register(uname))
		{
		header(location: login.php);
		}
?>
<html>
<body>
WELCOME 
</body>
</html>

Re: LoigIn Issue

Posted: Thu Jan 12, 2012 9:47 am
by Tiancris
I think you missed session_start() in login.php and add quotes to session_register(uname) in welcome.php

By the way, the session_register () function is now deprecated, you should use $ _SESSION.

Re: LoigIn Issue

Posted: Thu Jan 12, 2012 10:07 am
by jayson.ph
hi Tiancris, thanks and i try earlier but it could be they same, i mean nothing happened.

Re: LoigIn Issue

Posted: Thu Jan 12, 2012 10:16 am
by jayson.ph
i tried like this..

Code: Select all

                        session_start();
			session_register("uname");
                        session_register("pwd");
                                header("location: welcome.php");


AND like this

Code: Select all

                        session_start();
			$_SESSION("uname");
                        $_SESSION("pwd");
                                header("location: welcome.php");

Re: LoigIn Issue

Posted: Thu Jan 12, 2012 12:25 pm
by Tiancris
$_SESSION is an array, not a function, you have to assign some value:

Code: Select all

session_start();
$_SESSION['uname'] = $_POST['uname'];
$_SESSION['pwd'] = $_POST['pwd'];
And:

Code: Select all

session_start();
if (!isset($_SESSION['uname'])) {
  header("Location: login.php");
  exit;
}

Re: LoigIn Issue

Posted: Thu Jan 12, 2012 9:51 pm
by jayson.ph
Please another adivce, thanks

Re: LoigIn Issue

Posted: Fri Jan 13, 2012 2:19 am
by jayson.ph
will Tiancris, thank for code and for the idea, its help me and learn a lot. and now it works/ solve . thankz

Re: LoigIn Issue

Posted: Fri Jan 13, 2012 7:30 am
by Tiancris
:D