<?php
$tname=$_POST['tname'];
$uname=$_SESSION['user'];
include('db_connect.php');
$sql="SELECT marks FROM marks WHERE uname='$uname' && tname='$tname'";
$data=mysql_query($sql);
$marks=$data['marks'];
echo $marks;
echo $uname;
echo $tname;
?>

When I am trying to retrieve data marks is not retrived its displaying as "Marks" Please help

Member Avatar for diafol

You need to use

$d = mysql_fetch_assoc($data);
$marks = $d['marks'];

$data is a result object. You have to fetch array from it like follows

$row = mysql_fetch_array($data, MYSQL_ASSOC);
$marks = $row['marks'];
echo $marks;

OR you can replace $row = mysql_fetch_array($data, MYSQL_ASSOC); by $row = mysql_fetch_assoc($data);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.