I'm getting the following error while trying to read from a database. It is connecting and pulling data. I get this error for each record in the db.
Notice: Undefined index: user in /var/www/html/test.php on line 28
Line 28 refers to:
echo $row['user'] . "<br>";
Here is all the code:
<?php
$dbhost = "localhost";
$db = "mydb";
$dbuser = "mydbuser";
$dbpass = "mydbpassword";
$link = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($db, $link);
if (!$db_selected) {
die ('Cannot use database : ' . mysql_error());
}
$result = mysql_query("SELECT * FROM poc_user_data");
if (!$result) {
die('invalid query: ' . mysql_error());
}
$num_rows = mysql_num_rows($result);
if($num_rows > 0){
while($row = mysql_fetch_array($result)){
echo $row['user'] . "<br>";
}
}
else{
echo "no rows found";
}
?>
[\PHP]