注釋:以下代碼中,表單input的name和id值,需要和數(shù)據(jù)庫中的值一樣。dede_diyforms是數(shù)據(jù)表名稱,請自行更換
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>自定義表單查詢</title>
</head>
<body>
<form enctype="multipart/form-data" method="post">
考生姓名:<input type="text" name="aa" id="aa"/><br><br>
身份證號:<input type="text" name="bb" id="bb"/><br><br>
<input type="submit" value="查詢" /><br><br>
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {//接收表單傳遞過來的值
require_once(dirname(__FILE__)."/include/common.inc.php");//鏈接織夢數(shù)據(jù)庫(此文件必須在根目錄,如果在二級目錄,/include需要改為/../include)
$conn = mysqli_connect($cfg_dbhost, $cfg_dbuser, $cfg_dbpwd, $cfg_dbname)or die("數(shù)據(jù)庫鏈接失敗".mysqli_error());//判斷數(shù)據(jù)庫是否鏈接成功
mysqli_set_charset($conn,"utf8");//指定輸出結(jié)果的編碼為utf8 (請注意,是utf8,不是utf-8)
$sql = "select * from dede_diyforms where aa='$aa' and bb='$bb'";//查詢數(shù)據(jù)庫中aa/bb字段是否等于表單提交的數(shù)值
if($res=mysqli_query($conn, $sql)){
if(mysqli_num_rows($res)>0){//判斷是否有符合查詢條件的結(jié)果
while ($row= mysqli_fetch_array($res))//循環(huán)查找所有結(jié)果,<a href="http://www.jygsgssxh.com/" target="_blank"><u>織夢模板</u></a>www.xiuzhanwang.com
echo "<div>準(zhǔn)考證號:$row[cc]<div><div>考試場地:$row[dd]<div>";//輸出符合條件的指定數(shù)據(jù)
}else{//如果沒有查詢到結(jié)果
echo "沒有查詢到數(shù)據(jù),請核實考生信息是否正確";//無結(jié)果時的提示
}
}
};
?>