<?php
session_start();
ob_start();
$host="localhost"; // Host name
$username="*"; // Mysql username
$password="*"; // Mysql password
$db_name="vragenlijst"; // Database name
$tbl_name="leerlingen"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE gebruikersnaam='$myusername' and wachtwoord='$mypassword'";
$result=mysql_query($sql);
$sql1="SELECT * FROM leerlingen WHERE gebruikersnaam='$myusername' and wachtwoord='$mypassword'";
$geslacht=mysql_query($sql1);
$row = mysql_fetch_array($geslacht);
echo $geslacht['leraar'];
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername;
$_SESSION["mypassword"] = $mypassword;
/*if($geslacht = 'm') {
header("location:vragen2m.html");
} else {
header("location:vragen2v.html");
}
*/
}
else {
echo "Verkeerde gebruikersnaam of wachtwoord";
}
ob_end_flush();
?>
mysql表'leerlingen'包含一个名为'geslacht'的列。 'geslacht'包含值'm'或值'v'。我知道'mysql_query($ sql1)'命令返回数据,这些值存储在数组中。当我回显查看查询结果时,php代码返回错误消息“资源ID#4”。 我尝试了几种提取数据的方法,但每次我们收到错误消息或只是一个空白页面。 提前谢谢!
答案 0 :(得分:2)
$row = mysql_fetch_array($geslacht);
echo $geslacht['leraar']; // this is the error because $geslacht is your resource and not your array
$geslacht
//是您的资源
$row
//是您的数组
您可以print_r($row);
输出数组。
如果你的数组有一个名为leraar的字段,你可以echo $row['leraar'];
。