[英]not able to find the error in a simple php-mysql query
在這個簡單的代碼中,我必須從具有fname列和其他一些列的表人員中檢索,我無法通過匹配fname進行檢索。 代碼:->
<!DOCTYPE html>
<html>
<title>fname searched!!!</title>
<body>
<div id="container" style="width:1500px"> <! div for main header ... orange portion>
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">LIST OF SEARCHED ACTIVE SERVICE PERSONNEL</h1>
<figure>
<img src="personnel_head.jpg" alt="botg" width="1400" height="250">
<figcaption>.....tracking records......</figcaption>
</figure>
</div>
<div id="menu" style="background-color:#FFD700;height:1050px;width:200px;float:left;">
<! div for left side menus ... yellow portion>
candidate_reg_form<br>
view enrolled persons<br>
list of ammunitions<br>
character_certificate<br>
list_dependents<br>
regiments<br>
current serving general<br>
<b>SEARCH<b><br>
</div>
<! div for main container ... grey portion>
<div id="content" style="background-color:#EEEEEE;height:1050px;width:1300px;float:left;">
<BODY>
<fieldset>
<h1>active service personnel's details=>></h1>
<?php
$con=mysqli_connect("localhost","sumit","","ind_army");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$fname2=$_POST['fname2'];
echo"<br>";
$result = mysqli_query($con,"SELECT * FROM 'personnel' WHERE fname=$fname2");
echo "<table border='1'>
<tr>
<th>FNAME</th>
<th>MNAME</th>
<th>LNAME</th>
<th>SERV_NO</th>
<th>SEX</th>
<th>RANK</th>
<th>BDATE       </th>
<th>R_NAME</th>
<th>SALARY</th>
<th>ADDRESS</th>
<th>SUPER_SERV_NO</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['mname'] . "</td>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td>" . $row['SERV_NO'] . "</td>";
echo "<td>" . $row['sex'] . "</td>";
echo "<td>" . $row['RANK'] . "</td>";
echo "<td>" . $row['bdate'] ."</td>";
echo "<td>" . $row['R_NAME'] . "</td>";
echo "<td>" . $row['salary'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['super_serv_no'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
<br><br>
<font color="orange">enter the service no for knowing his/her service ` `details</font>
<!-- form to get key detail of personnel record in database -->
<form name="form" method="POST" action="http://localhost/search_per2.php">
serv_no<input type="text" name="search"> <br><br>
<input type="submit" value="submit">
</form>
<font color="blue">enter the service no for knowing his/her depedents</font>
<!-- form to get key detail of dependent record in database -->
<form name="form" method="POST" action="http://localhost/dep_search.php">
serv_no<input type="text" name="search2"> <br><br>
<input type="submit" value="submit">
</form>
<LABEL>
<form action="http://localhost/indarmy.php" method="post" >
<form>
<input type="SUBMIT" name="HOME" VALUE="HOME"></label>
</FORM>
</FIELDSET>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright © indarmy.com</div>
</div>
</body>
</html>
它給出的錯誤是:->警告:mysqli_fetch_array()期望參數1為mysqli_result,在66行的C:\\ xampp \\ htdocs \\ search_fname.php中給出布爾值
更改
while($row = mysqli_fetch_array($result))
至:
while($row = mysqli_fetch_assoc($result))
如果循環獲取結果作為數組你通過數組有循環,而得到行作為關聯數組,你將能夠引用列,你在你的循環,現在做的事情。
要查看發生了什么錯誤:
if(!$result)
{
echo "error: ".mysqli_error($con);
}
在查詢執行之后。
這可能是SQL中的東西。
您認為可以肯定嘗試的一種方法是,通過在搜索字符串$ fname周圍添加引號來清理查詢。 我很確定不能使用單引號,所以我用反引號代替了它們。
$result = mysqli_query($con,"SELECT * FROM `personnel` WHERE fname = '$fname2' ");
嘗試如下查詢:
$result = mysqli_query($con,"SELECT * FROM `personnel` WHERE fname='$fname2'");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.