无法从php / mysql中的数据库中检索结果

时间:2015-02-17 09:12:52

标签: php mysql

我使用简单的代码从数据库表中检索数据,但没有得到它总是显示的结果"没有找到结果"。 表格结构 rollno Varchar(50)主键, 名字Varchar(100), fname Varchar(100), mname Varchar(100), 课程Varchar(100), 持续时间Varchar(100), 地址Varchar(100), 图像blob。

HTML表格代码

<form name="input" action="q.php" target="display" method="post" >

                        Roll No: <input type="text" name="name">
                        <input type="submit" name="submit" value="Submit">
                        </form>

PHP代码

<?php

    if (isset($_POST['name'])) {


$con=mysqli_connect("mysql.1freehosting.com","u890130056_certi","samsungk2","u890130056_certi");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$name = htmlspecialchars($_POST['rollno']);
{

$result = mysqli_query($con,"SELECT * FROM certificate where rollno ='$name'");



 if(mysqli_num_rows($result)>0){

while($row = mysqli_fetch_array($result))
{

echo "<tr>";
echo "<td>" . $row['rollno'] . "</td>";
echo "<td>" . $row['course'] . "</td>";
echo "<td>" . $row['duration'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['mname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";

echo "<td>";?><img src="<?php echo $row["image"]; ?> " height="100" width="100"> <?php echo "</td>";

echo "</tr>";

}

}
else
{
echo "<tr><td colspan='4'>&nbsp;No Data Found , Please check your registration no. or contact the institute for clarification. &nbsp;".$line.'</td></tr>';
}




mysqli_close($con);
}}
?>

1 个答案:

答案 0 :(得分:0)

name = htmlspecialchars($_POST['rollno']);

你在哪里得到这个'rollno ?? 我不明白为什么你通过张贴['rollno']来保存结果,因为你的领域的名字是'名字'。

更改此行

$name = htmlspecialchars($_POST['rollno']);

$name = htmlspecialchars($_POST['name']);