在这方面,我是php开发的新手,所以在这里我坚持自己的代码。它没有按预期工作。这是我的代码,在第46行出现错误,但我实际上不知道错误是什么,请帮助我找出来
<?php
session_start();
if(isset($_SESSION['uid']))
{
echo "";
}
else
{
header('location: ../login.php');
}
?>
<?php
include ('header.php');
include ('titlehead.php');
?>
<table align="center" border="1">
<form action="" method="post">
<tr>
<th>Enter Standerd</th>
<td><input type="number" name="standerd" placeholder="Enter Standerd"/></td>
<th>Enter Student Name</th>
<td><input type="name" name="stuname" placeholder="Enter Student Name"/></td>
<td colspan="2"><input type="submit" name="submit" value="Search"></td>
</tr>
</form>
</table>
<table align="center" width="80%" border="1" style="margin-top:10px;">
<tr style="background-color:#000; color:#fff;">
<th>No.</th>
<th>Image</th>
<th>Name</th>
<th>Roll No.</th>
<th>Edit</th>
</tr>
<?php
if(isset($_POST['submit']))
{
include('../dbcon.php');
$standerd = $_POST['standerd'];
$name= $_POST['stuname'];
$qry="SELECT * FROM `student`where standerd='$standerd' AND stuname='$name'";
$run=mysqli_query($con,$qry);
if(mysqli_num_rows($run)<1)
{
echo "<tr><td>No Records Found</td></tr>";
}
else
{
$count=0;
while($data=mysqli_fetch_assoc($run))
{
$count++;
?>
<tr>
<td><?php echo $count;?></td>
<td><img src="../dataimg/<?php echo $data['image'];?>" style="widht:50px;" height='50px';/></td>
<td><?php echo $data['name']; ?></td>
<td><?php echo $data['rollno']; ?></td>
<td>Edit</td>
</tr>
<?php
}
}
}
?>
</table>
答案 0 :(得分:0)
您的查询有错误。我相信您忘记了student
和where
之间的空格。
SELECT * FROM `student` where standerd='$standerd' AND stuname='$name'
否则请检查您的凭据。
答案 1 :(得分:0)
只需将您的PHP代码替换为以下代码,
<?php
if(isset($_POST['submit']))
{
include('../dbcon.php');
$standerd = $_POST['standerd'];
$name= $_POST['stuname'];
$qry="SELECT * FROM `student` where standerd='$standerd' AND stuname='$name'";
$run=mysqli_query($con,$qry);
$result = mysqli_num_rows( $run );
if( $result < 1 ) {
echo "<tr><td>No Records Found</td></tr>";
} else {
$count=0;
while($data=mysqli_fetch_assoc($run)) {
$count++;
?>
<tr>
<td><?php echo $count;?></td>
<td><img src="../dataimg/<?php echo $data['image'];?>" style="widht:50px;" height='50px';/></td>
<td><?php echo $data['name']; ?></td>
<td><?php echo $data['rollno']; ?></td>
<td>Edit</td>
</tr>
<?php
}
}
}
?>
我希望这能解决您的问题。