搜索MySql数据库并查看结果

纳西姆·乌丁(Nasim Uddin Ahmmad)

我已经上传了一个简单的php注册表格(详细信息在下面),并且效果很好。但是现在我想创建一个搜索框,以便我的学生可以使用“注册号”来验证他们的注册。[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();
?>
扎卡里亚·阿卜杜拉(Zakaria Abdalla)

只是该方案在其中创建一个html表单make文本框,该文本框将例如注册发送到php文件,该文件获取文本,并在该文件内执行写查询,该查询使用select语句在数据库中搜索该文本,然后在表内进行输出,如下所示

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>    


?>

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章