displaying information from tabls rows. explained

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 7
Joined: Sat Aug 25, 2012 10:23 pm

displaying information from tabls rows. explained

Postby nichodiaz » Sat Aug 25, 2012 10:34 pm

I am trying to show the user logged in his information that he added at time of register. I have been pulling code from the internet and would like to understand it better so I can fix things on my own.

Currently when you log in it displays the most recent persons information that has registered on the site instead of showing the persons information that just logged in.

I do not understand what variables are being assigned and how exactly im telling the variable that it now stands for what ever row im attaching it to.

This is my code that is displaying the wrong information. Please explain each line and code such as whats a variable and whats just an embedded command. Then if you could explain why it is showing the information from who last registered instead of the person currently logged in...

$link = mysql_connect("localhost", "root", "");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM users" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);


while ($i<$num_rows )

$first=mysql_result($result, $i,"first");



echo "<b>Username: $username</b><br>Phone: $phone<br>Mobile: $mobile<br>E-mail: $email<br>Web: $web<br><hr><br>";



php-forum Active User
php-forum Active User
Posts: 481
Joined: Fri Aug 05, 2011 9:53 am

Re: displaying information from tabls rows. explained

Postby NigelRen » Sun Aug 26, 2012 7:04 am

The problem is that you are simply reading all of the records from the database and displaying the last record.

What you probably want is to change the select...

Code: Select all

$result = mysql_query( "SELECT * FROM users WHERE username ='".$username."'" );

This limits the records according to the username entered. You will need to fetch this field from the form where the user enters the data ( using either $_POST or $_GET ).

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 3 guests