I have a very simple script that pulls data from a mysql db, However when I run it there is no output, I am setting the get request to the correct value related to the row and when i run the SQL query in PHPmyadmin it runs as expected.
my code;
session_start();
require_once 'includes/sessions.inc.php';
require_once 'includes/config.inc.php';
if(!isLoggedIn())
{
echo "not logged in";
}
else
{
//Connect to DB
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
$id = $_SESSION['userid'];
$contactid = $_GET['contactid'];
//Get Data from DB
$query = "SELECT id, First_name, Last_name, email_addres, phone_number, photo, owner FROM tbl_contcats where id = '$contactid';";
$result = mysql_query($query) or die(mysql_error());
echo '<img src="./contacts/'.$result['photo'].'"/><br>';
echo 'First name:'.$result['First_name'].'<br>';
echo 'Second name:'.$result['First_name'].'<br>';
echo 'Email Address:'.$result['First_name'].'<br>';
echo 'phone_number'.$result['First_name'].'<br>';
}
?>
ps; any feed back on how I can improve my code/clean it up is apericated
mysql_queryreturns a resultset, not a row. You have to iterate through the resultset to get your rows, using functions likemysql_fetch_assoc.