Dear Php Pro

I have a small problem ; i cant echo the username in my script ;and i have tried all the echo and username is not being shown
below my script i will put 2 files ;one is called login.php and the other is member.php; in member.php i can not echo username from sql ;please any idea

login.php
<?php ob_start() ?>
<?php
session_start();

$UName = $_REQUEST['UserName'];
$PWD = $_REQUEST['PWD'];

$_SESSION['login'] = "1";


$dbcnx = mysql_connect('myhost', '', '');
if (!$dbcnx) {
 header ('Location: index.php?Msg=2');
 exit();
}

//we could connect to the database

//Select the DB we want to deal with
mysql_select_db ("mydatabase");

//Now we have to check if the username and password entered are correct
$MyDate = date("Y-m-d", time());
$sql="Select * from Member where UserName='$UName' AND PWD='$PWD' AND ExpiryDate>='$MyDate'";
//echo $sql;
//exit();

$result=mysql_query($sql);
$num=mysql_numrows($result);


	if($num!=0)
	{


		$RegistrationType = mysql_result($result,0,"RegType");
		$login = $RegistrationType;
		session_register("login");

		$logID = mysql_result($result,0,"MemberID");
		session_register("logID");

		$Email = mysql_result($result,0,"Email");


		session_register("Email");

		//redirect users depending on registration type
		if($RegistrationType=="1" || $RegistrationType=="3")
		header ('Location: Members.php');
		if($RegistrationType==2)
		header ('Location: MembersIII.php');
		exit();
	}
	else
	{
		 header ('Location: index.php?Msg=1');
		 exit();
	}

header ('Location: index.php?Msg=1');
?>

<?php ob_end_flush() ?>
members.php
<?php ob_start() ?>
<?php
session_start();


//Check to see if the user was already logged on
if ($_SESSION["login"] !=1 && $_SESSION["login"] !=3)
{
header ('Location: index.php?Msg=3');
}
//echo $_SESSION["login"];

if isset($UserName) {echo $UserName; }
If (isset($_POST['UserName']))


//Connect to DB and Get the mailing list
$dbcnx = mysql_connect('myhost', '', '');



//we could connect to the database
//Select the DB we want to deal with
mysql_select_db ("mydatabase");
?>

Recommended Answers

All 2 Replies

In members.php

// this will never do anything, you're never defining $UserName
if isset($UserName) {echo $UserName; }

// This does not do what you think it does
If (isset($_POST['UserName']))

//Connect to DB and Get the mailing list
$dbcnx = mysql_connect('myhost', '', '');
// This is what it actually does
If (isset($_POST['UserName'])) {
  //Connect to DB and Get the mailing list
  $dbcnx = mysql_connect('myhost', '', '');
}

dear Shawn , it seems this is the second time u have been helpful and i appreciate that; what do u think should i write in such script to echo the username when client log in; in sql i have it written in a member (table) and UserName thanks again really

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.