0

下面是我的代码:

session_start();
include_once "config.inc.php";
$tbl_name="members";

 $username=$_SESSION['username'];
$sql = "SELECT quiz1mark, quiz2mark, quiz3mark FROM $tbl_name WHERE username='$username'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query, MYSQL_ASSOC);

然后,在页面下方:

<p><?php echo $data; ?></p>

这会生成一个通知:Notice: Undefined variable: data in F:\xampp\htdocs\quiz_home.php on line 35

我已经明确定义了变量,但不确定是什么导致了这个问题。

***Contents of config.inc.php***:

$host="localhost";
$username="root";
$password="";   //the default installation of xampp does not include a mysql password
$db_name="bda";
//connect to the database using the above information (variables)
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select database");
4

1 回答 1

3

尝试的结果是什么?:

var_dump($data);
于 2012-08-09T00:53:39.643 回答