搜索 MySql 数据库并查看结果

Search MySql Database & view Result

我已经上传了一个简单的 php 注册表(详细信息如下)并且效果很好。但现在我想创建一个搜索框,以便我的学生可以使用 "Registration Number" 验证他们的注册。 [Exp: http://www.nbceindia.in/student-verification.php ] 谁能帮我创建代码。

提前致谢。

详情:

1. entry.php

<!DOCTTYPE html>
<head><link rel="stylesheet" type="text/css" href="style/style.css"></head>
<title>Registration</title>
<body>  

<form name="form1" method="post" action="register_ac.php">

    <li>Registration No.<input type="text" name="registration" class="#" id="registration" maxlength="8"/></li>
    <li>First Name<input type="text" name="firstname" class="#" id="firstname"/></li>
    <li>Surname<input type="text" name="surname" class="#" id="surname"/></li>
    <li>Course Code<input type="text" name="course" class="#" iid="course" maxlength="7"/></li>
    <li>Duration (Months)<input type="text" name="duration" class="#"  id="duration"/></li>
    <li>Mobile<input type="text" name="mobile" class="#" id="mobile" maxlength="10"/></li>
    <li>Addressline1<input type="text" name="addressline1" class="#" id="addressline1"/></li>
    <li>Addressline2<input type="text" name="addressline2" class="#" id="addressline2"/></li>
    <li>City<input type="text" name="city" class="#" id="city"/></li>
    <li>Postcode<input type="text" name="postcode" class="#"  id="postcode" maxlength="6"/></li>


    <input type="submit" id="textarea" name="submit" value="Submit" class="button"/>
</form>

</body>
</html>

2。 register_ac.php

<?php

$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database_name"; // Database name
$tbl_name="table_name"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$registration=$_POST['registration'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$course=$_POST['course'];
$duration=$_POST['duration'];
$mobile=$_POST['mobile'];
$addressline1=$_POST['addressline1'];
$addressline2=$_POST['addressline2'];
$city=$_POST['city'];
$postcode=$_POST['postcode'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(registration, firstname, surname, course, duration, mobile, addressline1, addressline2, city, postcode)
VALUES('$registration', '$firstname','$surname','$course','$duration','$mobile','$addressline1','$addressline2','$city','$postcode')";
$result=mysql_query($sql);


// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

只是场景创建一个 html 表单在其中创建文本框,例如将注册发送到 php 文件,该文件获取文本并在该文件中写入查询以搜索该文本数据库使用 select 语句,然后在 table 中像这样

进行输出

search.html {

<li>ID.<input type="text" name="id" class="#" id="id" maxlength="8"/></li>


<input type="submit" id="textarea" name="submit" value="Submit" class="button"/>
</form>
}


disp.php{
<?php

$id1=$_GET['id'];
$con = mysql_connect("host","username","password");
if(!$con){
die('<h1>Could not connected '. mysql_error().'<br>');
}
$sqlStmt="SELECT * FROM table_name  WHERE Id='$id1'";

mysql_select_db('db_name');

$res=mysql_query($sqlStmt,$con);
?>
<table border="1" bgcolor="cyan">
<tr bgcolor="yellow">
    <th>Id</th> <th>FirstName</th> <th>LastName</th>
</tr>
<?php
while($user=mysql_fetch_array($res)){
?>
<tr>
    <td><?php echo $user['Id'];?></td>    
    <td><?php echo $user['First name'];?></td>    
    <td><?php echo $user['sur name'];?></td>    

</tr>    
<?php        
}    
?>    
</table>    


?>

}