如果从数据库读取条目的语句将不显示

时间:2015-05-09 21:30:00

标签: php html mysqli

以下代码包含取决于usertypestatus的if语句。它不会显示任何内容。在上面的代码中,我有usertype==1status==1,它正常工作但下面的代码不起作用。有什么建议?请忽略我的代码,因为我是初学者,代码很乱。

}  else if ($usertype == 2) { 
$server1 = "localhost";
$user1 = "r";
$pass1 = "";
$db1 = "";
$db4 = "";
$user5 = $_SESSION['username'];
$mysqli  = new Mysqli($server1, $user1, $pass1, $db1) or mysqli_error($mysqli);
$mysqli6  = new Mysqli($server1, $user1, $pass1, $db4) or mysqli_error($mysqli);
$name2= $mysqli6->query("SELECT name FROM head WHERE username= '$user5'")->fetch_object()->name2;  
$status2 = $mysqli->query("SELECT status FROM Overrides WHERE head = '$name2'")->fetch_object()->status2; 
$headforms = $mysqli->query("SELECT * FROM Overrides WHERE head = '$name2' "); 

$num_rows2 = mysqli_num_rows($headforms);

 if ($status2 == 2) {

echo "Overrides today: " . $num_rows2; 
    while($row2 = mysqli_fetch_array($headforms)) {
         echo "<br /><br />First Name: " . $row2['name'] . "<br />";
         echo "<br />Middle Name: " . $row2['mname'] . "<br />";
         echo "<br />Family Name: " . $row2['fname'] . "<br />";
         echo "<br />Student ID: " . $row2['sid'] . "<br />";
         echo "<br />Scolarship: " . $row2['sc'] . "<br />";
         echo "<br />Phone No: " . $row2['phone'] . "<br />";
         echo "<br />Email: " . $row2['email'] . "<br />";
         echo "<br />Class: " . $row2['class'] . "<br />";
         echo "<br />Section: " . $row2['section'] . "<br />";
         echo "<br />Semester: " . $row2['semester'] . "<br />";
}
}

?> 

关于数据库条目和数据,我检查了它们,我100%确定它应该显示正确的信息。

我做了一个测试:我尝试了print_r($status2);print_r($name2);,但是页面是空的,可能问题出在userype == 2上,因为它没有显示任何内容。

错误:

Notice: Undefined property: stdClass::$name2 in /home/aukwizcq/public_html/override.php on line 310

Notice: Trying to get property of non-object in /home/aukwizcq/public_html/override.php on line 311

0 个答案:

没有答案