...

View Full Version : Failed to retrieve certain column data from database



pelehelp
03-28-2009, 10:39 AM
Hi
Thanks a lot for the guidlines, is very helpful and I realise my mistakes too. Now i have another problem is that I can't retrieve certain column (full_name and ic_number)from the database into a table form. I wondering what is my problem here.



<?php
//Connect to the MySQL server
$db_host = "localhost";
$db_username = "root";
$db_password = "fsktm";
$server = mysql_connect($db_host,$db_username,$db_password)or die("Could not connect!/n");

//Select a database that has created
$db_name = "cinema";
mysql_select_db($db_name)or die("Could not select the database $db_name!\n");


//Retrieve or select the data
$retrieve = mysql_query("SELECT *FROM user") or die(mysql_error());

echo"<table border = 1 width = 100% height = 100% style = 'background-color:#F0F8FF;'>
<tr>
<th>Username</th>
<th>Password</th>
<th>Full Name</th>
<th>IC Number</th>
<th>Telephone</th>
<th>Email</th>
<th>History</th>
</tr>";

//Display the data from the database in a table using aray
while($row = mysql_fetch_array($retrieve))
{
echo "<tr>";
echo"</td><td>";
echo $row['username'];
echo "</td><td>";
echo $row['password'];
echo "</td><td>";
echo $row['fullname'];
echo "</td><td>";
echo $row['ic'];
echo "</td><td>";
echo $row['telephone'];
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['history'];
echo "</tr>";
}

echo "</table>";

mysql_close($server);
?>

abduraooft
03-28-2009, 10:47 AM
Put
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL); at the top of your code, to reveal all errors (including the one in your query).

pelehelp
03-28-2009, 10:58 AM
After I include the codes that u have suggested, the error mas shows that "Undefined index: fullname and ic", but I ady checked the database, both of the fullname and ic do show in the database; it only failed to be shown in the table created.So, I'm still wonder what was the problem occured?

abduraooft
03-28-2009, 11:06 AM
Didn't you get a mysql error message?

$retrieve = mysql_query("SELECT *FROM user") or die(mysql_error()); should be

$retrieve = mysql_query("SELECT * FROM user") or die(mysql_error());

pelehelp
03-28-2009, 11:30 AM
Yup, it displayed an error msg 'Undefined index:fullname and ic'.Therefore, the data from these two columns couldn't be displayed in table. But when I cheched thro the database, the data can be shown.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum