Jump to content

session continues but does not echo members???


rdkd1970

Recommended Posts

Okay I tried this codes and got a Welcome no name but it goes to the next private pages. so I think it somehow moved from the everyone in the db to welcoming no one but I think it must be the layout of the echo Welcome, firstname.

 

Here is my new codes

 

$query = "SELECT id, firstname FROM `Members` WHERE id='" . $_SESSION['id'] . "'";
$result = mysql_query($query);
if($result){
  // or do it the way you have if you prefer "(!$result)"
        $row=mysql_fetch_assoc($result);
		       echo "Welcome, {$row['firstname']}";
			    }else{
					     $message  = 'Invalid query:' . mysql_error() . "\n";
						       $message .= 'Whole query:' . $query;
							          die($message);
									  }
									   }  
  //Free the resources associated with the result set
  mysql_free_result($result);


 

this is my results live

 

Welcome,

 

 

 

Your new Member accounts lets you enter the members only section of our web site. You'll find special discounts, a profile of matches, live advise from experts, and much more.

 

Your new Member ID and password were emailed to you. Store them carefully for future use.

 

 

Link to comment
Share on other sites

How do you set $_SESSION['id'] as you mentioned.???

$_SESSION['id'] = $row['id'];

 

but in order for it to work properly you'll have to put that snippet BEFORE the query, yet inside the while loop (or else $row won't exist).  In other words, you should have $_SESSION['id'] set before you even run a query with it.

// Set the users session ID
include("Connections/connect_to_mysql.php");

This is where the session should be set... you probably have something wrong in connect_to_mysql.php

 

 

Link to comment
Share on other sites

I have the same connect to db as the form which is uploading the tested names.

 

I am now getting a welcome, " I just need to work on the echo correctly. thanks for all your help I so appreciate it.

 

here is my codes for the echo

 

$row=mysql_fetch_assoc($result);
		       echo "Welcome, " . $row['firstname'] . "";

Link to comment
Share on other sites

Still not getting any results with my if statements I am trying to echo out welcome, firstname but when I adjust my if statements it either welcomes all names in db, just welcome or nothing but it does continue with the private pages.

 

Here is my latest codes

 

<?php
session_start();


ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>		
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
<style type="text/css">
.background {color: #B56AFF;
}
</style>
</head>

<body>
<p>

<?php
/* Program: login.php
* Desc:	Displays the new member welcome page. Greets
*			member by name and gives a choice to enter
*			restricted section or go back to main page.
*/ 
if (isset($_SESSION['id'])) {	            
// Set the users session ID
  $id=$_SESSION['id'];
   
include_once ("Connections/connect_to_mysql.php");


//Formulate Query
//This is the best way to perform an SQL query
$query = "SELECT id, firstname FROM `Members` WHERE id={$_SESSION['$id']}";
$result = mysql_query($query);
$numrows=mysql_num_rows($result);
//Check result
//This shows the actual query sent to MySQL and the error. Useful for debugging.
if(!$result){
	$message = 'Invalid query:' . mysql_error() . "\n";
		$message .= 'Whole query:' . $query;
			die($message);}
			//Use result
			//Attempting to print $result won't allow access to information in the resource
			//One of the mysql result functions must be used
			//See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
			if($id==$firstname){

					echo "Welcome, '{$row['firstname']}'";

			}
					//Free the resources associated with the result set
					mysql_free_result($result);

}
?>
</p>
<p>  </p>
<p>Your new Member accounts lets you enter the members only section
  of our web site. You'll find special discounts, a profile of matches,
live advise from experts, and much more.</p>
<p>Your new Member ID and password were emailed to you. Store them
carefully for future use.</p>
<div style="text-align: center">
<p style="margin-top: .5in; font-weight: bold">
Glad you could join us!</p>
<form action="profile.php" method="post">
<input type="submit"
	value="Enter the Members Only Section">
	</form>
<form action="index.php" method="post">
<input type="submit" value="Go to Main Page">
</form>		
	</div>
</body>
</html>

 

At a lost :'(

Link to comment
Share on other sites

Ok, I just decided to restructure your code rather than tell you everything wrong with it, I put a few comments in there to explain a few things.

session_start();
ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>





Welcome
<br />
	.background {color: #B56AFF;<br />
}<br />




if (isset($_SESSION['id'])) {           
// Set the users session ID

   
include_once ("Connections/connect_to_mysql.php");
$id=$_SESSION['id'];

//Formulate Query
//This is the best way to perform an SQL query
$query = "SELECT id, firstname FROM `Members` WHERE id='$id'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
//Check result
//This shows the actual query sent to MySQL and the error. Useful for debugging.
if(!$result){
	$message = 'Invalid query:' . mysql_error() . "\n";
	$message .= 'Whole query:' . $query;
	die($message);
}
/// Since the script die()'s if the query fails, you don't need an else statement.
/// We can assume from here on out that the query passed and the SESSION id was set.
	$row = mysql_fetch_assoc($result);
	mysql_free_result($result);
                echo "
Welcome, " . $row['firstname'] . "";
}
?>

Your new Member accounts lets you enter the members only section
  of our web site. You'll find special discounts, a profile of matches,
live advise from experts, and much more.

Your new Member ID and password were emailed to you. Store them
carefully for future use.



Glad you could join us!













Link to comment
Share on other sites

alright then, so if the Query is returning empty, it most likely means either:

- the id doesn't exist

- or the id hasn't been set.  $_SESSION['id'] has no value.

 

Which makes me wonder how it gets past that first IF statement in the first place.

Link to comment
Share on other sites

if (isset($_SESSION['username'])) {

You check for this variable but I don't see where you actually declared it.

SELECT id, firstname FROM `Members` WHERE id=idLIMIT 1

 

There is no space between id and LIMIT.  Also, the fact that you have id=id in your query answers this puzzle.  Essentially, that query says Get all users whose id is equal to their id... which is all of them.

So now I'm back to my second post on this thread.. or third I can't remember.

 

You never set $_SESSION['id'] to contain an actual id.  Once you do that, you should have a working query... you won't even need that LIMIT duct tape.

$_SESSION['id'] has no value.

 

Post your "empty result" query here.  You should notice that there is no id being compared.

Link to comment
Share on other sites

I got it. After the registration page, I created a page that had welcome for the member to click on a login button which takes them to the login page. After they login in it goes to the first private page which echos their name. At the top of the welcome, and member is the session_start with the $_SESSION[username] coding. Which goes on all pages that are private.

 

1. Form.php to

2. Register_success to

3. Login_form to

4. Login_users to

5. Access_denied (if $_SESSION) does not recognize the login member

6. Member (if the login worked as the member registered)

7. Login_failed if no username or password.

 

If anyone wants these scripts let me know.... Thanks to everyone that helped me in getting it done.  :D :D

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.