Jump to content

[SOLVED] simple echo statement not working


sandbudd

Recommended Posts

I am just wanting to display the results when one logs in...thought it should be a simple echo statement but not working

 


<?php
// check the login details of the user and stop execution if not logged in
if(!isset($session['userid'])){
echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;
}

$row=mysql_fetch_object(mysql_query("select * from signup where userid='$session[userid]'"));



echo $row['firstname'];
echo $row['lastname'];
?>

Link to comment
Share on other sites

changed and same results and it is using sessions just showing the code that did not work

Have you called session_start() at the very top of your script? eg

 

<?php
session_start();

//code for page here
...

 

Also where/how are you defining your session variables?

Link to comment
Share on other sites

<?php
session_start();

$uid = $_SESSION['userid'];

// check the login details of the user and stop execution if not logged in
if($uid ==""){
echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;
}

$row=mysql_fetch_object(mysql_query("select * from signup where userid='{$uid}'"));



echo $row['firstname'];
echo $row['lastname'];
?>

Link to comment
Share on other sites

You should not be using session_register to create a session variable.

 

Instead you use the $_SESSION superglobal array. Example

 

page1.php

<?php
session_start();

$_SESSION['name'] = 'John Smith';
?>
<a href="page2.php">Go to Page2.php</a>

 

page2.php

<?php
session_start();

echo 'Hello! Your name is: ' . $_SESSION['name'];
?>

Link to comment
Share on other sites

here is the login page

 


<?php

include "include/session.php";

include "include/db.php";
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?php
$userid=mysql_real_escape_string($userid);
$password=mysql_real_escape_string($password);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM signup WHERE userid='$userid' AND password = '$password'"))){
if(($rec['userid']==$userid)&&($rec['password']==$password)){
 include "include/newsession.php";
            echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
     print "<script>";
       print " self.location='welcome.php';"; // Comment this line if you don't want to redirect
          print "</script>";

			} 
	}	
else {

	session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct  Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

}
?>

Link to comment
Share on other sites

You're not calling session_start() at the top of your login script. This function needs to be called on the first line of any page that uses sessions (this does not include files that are being included). It cannot be called after any output has been made (eg, text, html etc).

 

So add session_start() to your login script as highlighted below:

<?php

session_start();

include "include/session.php";

 

include "include/db.php";

//////////////////////////////

?>

 

Again $session needs to be $_SESSION within newsession.php

 

 

Link to comment
Share on other sites

Then this should work

 

$row=mysql_fetch_object(mysql_query("select * from signup where userid='{$session['userid]'}'"));

 

And I'm not even going to attempt to figure out how your $session varible is populated since it clearly isn't from the $_SESSION.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.