Re: Retrieving Name instead of ID
Posted by:
CyberSpatium
(67.170.181.---)
Date: July 02, 2006 02:23PM
There are a few reasons why your php code did not work. You have some some coding and some syntax errors in your script. I have edited your script to fix these problems.
Also, in your while loop, you are using mysql_fetch_row where you should have used mysql_fetch_array. mysql_fetch_row only returns one row of data, that is why your while loop only returned one result.
So, here is your edited and fixed code.
$host = 'localhost';
$user = 'root';
$pass = '_Your_Password_Here_';
$database = '_Your Database_Here_';
$dbconnect = mysql_connect ($host, $user, $pass) or die ('Unable to connect to the database.');
$dblink = mysql_select_db ($databse, $dbconnect);
$query ="SELECT * FROM sender WHERE fname = '" . $_POST['fname'] . "'";
$result = mysql_query($query, $dbconnect);
while($row = mysql_fetch_array($result, $dbconnect))
{
echo "id : " . $row[0] . " <br>";
echo "Name : " . $row[1] . " " . $row[2] . " <br>";
echo "Date : " . $row[3] . " <br>";
echo "Street & Apt # : " . $row[4] . " <br>";
echo "Street name : " . $row[5] . " <br>";
echo "city : " . $row[6] . " <br>";
}