954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

echo a mysql row based on the username

When a user logs in, the user is directed to a page called accountsummary.php. I have sessions enabled. I can successfully echo the inputed username, and echo the ENTIRE column of firstname and lastname for the entire table. The problem is that I do not want to echo the entire column or firstname and lastname. I only want to echo the firstname and lastname of the user name. Can anyone help with this?

This is the code for the login form on the index page:


Password

Remember Online ID



Need Help Logging In?
Get Your Login ID

this is the loginaction.php:
<?php
session_start( );

include("../scripts/cred.inc");

$OnlineID=$_POST['OnlineID'];
$Password=$_POST['Password'];
if ($OnlineID &&$Password)

{
$connect = mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect to mysql server.");

mysql_select_db("$dbDatabase") or die ("The Site down for scheduled maintenance. Please try back later. We are sorry for the inconvenience.");
}

else
header("location:../tryagain.php");


$query = mysql_query("SELECT * FROM swilregion132 WHERE OnlineID='$OnlineID'");

$numrows = mysql_num_rows($query);

if ($numrows !=0)
{

while ($row = mysql_fetch_assoc($query)) // code to log in
{
$dbOnlineID = $row['OnlineID'];
$dbPassword = $row['Password'];
}

if ($OnlineID==$dbOnlineID&&$Password==$dbPassword)
{
//ck echo "You're In!"; //if successfully logged in.
$_SESSION['username']=$OnlineID;
header("location:../accountsummary.php");
}
else
//ck echo "Incorrect Password"; //if failed to logged in.
header("location:../tryagain.php");
}

else
header("location:../tryagain.php");

?>

This is the accountsummary.php:
<?php
session_start( );

$dbServer = "192.168.1.10";
$dbUser = "root";
$dbPass = "password";
$dbDatabase = "hud";

$connect = mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect to mysql server.");

mysql_select_db("$dbDatabase") or die ("The Site down for scheduled maintenance. Please try back later. We are sorry for the inconvenience.");

//ck $query = "SELECT firstname, lastname FROM swilregion132" or die("Could not query mysql_query.");
$query = "SELECT firstname, lastname FROM swilregion132" or die("Could not query mysql_query.");
$result = mysql_query($query);

while($row = mysql_fetch_array($result))
{
echo " {$row['firstname']} " .
" {$row['lastname']}
";
//ck "Subject : {$row['subject']}
" .
//ck "Message : {$row['message']}

";
// "Message : {$row['message']}

";
}

//ck echo $_SESSION['username'];
?>

perceptiveforce
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

you could try using WHERE statement in your sql syntax..

$query = "SELECT firstname, lastname FROM swilregion132 WHERE onlineid = 'sessionname'" or die("Could not query mysql_query.");

This way its only pulling the information from that specific onlineid.
then u can use the rows for first and last name..
Hope this helps..

fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: