Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

displaying information from tabls rows. explained

Codes here !

Moderators: macek, egami, gesf

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

<?php
$db="login";
$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);

$i=0;


while ($i<$num_rows )


{
$first=mysql_result($result, $i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$username=mysql_result($result,$i,"username");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

$i++;

}

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

mysql_close($link);
?>


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

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 ).
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.