Jump to content

Welcome page welcomes everyone at same time


Recommended Posts

Can someone tell me how to get my $row to just have the person logging in to be welcomed presently when I test the page it is welcoming everyone of the test names????

this is the welcome page after the form. But it is picking up all tested members???

ini_set ("display_errors", "1");
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

/* 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

// Now let's initialize vars to be printed to page in the HTML section so our script does not return errors 
// they must be initialized in some server environments

$firstname = '';
$lastname = '';
$country = '';
$email = '';

//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);

//Check result
//This shows the actual query sent to MySQL and the error. Useful for debugging.

$message = 'Invalid query:' . mysql_error() . "\n";
$message .= 'Whole query:' . $query;
//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.
  echo "Welcome, {$row['firstname']}";
<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 action="index.php" method="post">
<input type="submit" value="Go to Main Page">

Link to comment
Share on other sites

you could try add ing limit 1 to the end of your sql


$query = "SELECT id, firstname FROM `Members` WHERE id={$_SESSION['id']} LIMIT 1";


also are you actually getting the session variable correctly, can you echo the value to check against the id's



Link to comment
Share on other sites

Echo $_SESSION['id'] - make sure it contains what you want it to. Your query SHOULDN'T be returning more than 1 row.


You shouldn't need the while loop either. You can use the below code instead, but don't change it over until you're actually getting a single row returned from your query.


list( $uid, $firstname ) = mysql_fetch_row($result)
echo "Welcome, $firstname";

Link to comment
Share on other sites

I get this message when adding the LIMIT code and to change the bottom code just states a syntax error on Welcome, $firstname.


Warning: mysql_query() [function.mysql-query]: Access denied for user 'ebermy5'@'localhost' (using password: NO) in /home/ebermy5/public_html/login.php on line 41


Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/ebermy5/public_html/login.php on line 41

Invalid query:Access denied for user 'ebermy5'@'localhost' (using password: NO) Whole query:SELECT id, firstname FROM `Members` WHERE id=id LIMIT 1

Link to comment
Share on other sites

Something's up with




Also, your $_SESSION['id'] doesn't actually have an ID.


There is SO much wrong here that should be obvious to someone who wrote the original script. If you're modifying someone else's code, please ask THEM for help. This is a forum for those who want to learn to program, not those who want to know just enough to make someone else's code work for them.

Link to comment
Share on other sites

I am not using anyones codes on the welcome page I just adjusted what others thought would work for me. I am trying to learn as much as you know but this is my first time trying to go live with coding. I try all suggestions giving to me as I know you guys know more than I know. I am just a newbie that thought it was going to work right away but found out that sometimes I come across a puzzle to fix. If I offended anyone I am sorry.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.