有关PHP提交表单

来源:百度知道 编辑:UC知道 时间:2024/05/29 14:49:58
我初学PHP,现在想用PHP做前台提交表单查询MYSQL数据库的页面,代码现如下,有很大问题,请高手帮我看看

这是前台HTML:
<form action="mysql.php" method="post" name="test"><p><span class="typle1">学号</span>
<input type=text name="s" size=42 maxlength=100>
</p>
<p>
<input name=botton1 type=submit value="搜索" />
</form>
这是PHP代码:
<?php
if ( $_POST['botton1'] == "搜索" ) {
$conn=mysql_connect("localhost","root","root")or die("Could not connect: ".mysql_error());
mysql_select_db("school")or die("Could not select database");
function rec_query($s){
$query="select sname,sc.sno,deptno,cname,cnum,cdept
from sc,student
where sc.sno=student.sno
and s

我补充一点 你的表单里使用的事POST 而第19行使用的是:$s=$_GET["s"];

还有至于你说提交表单时为下载PHP文件 我想一定是因为,你打开这个文件时用的是本地资源管理器的地址,类似于“file:///K:/www/match_school.php”,而PHP文件只有在本地主机配置成服务器以后,用本地还回地址打开:类似于:“http://localhost/match_school.php”;

有何很大问题呢?
只不过是你的函数rec_query没有调用mysql_query()也没有返回值
也就是:
function rec_query($s){
global $conn;
$query="select sname,sc.sno,deptno,cname,cnum,cdept
from sc,student
where sc.sno=student.sno
and sc.sno like '".$s."%'";
return mysql_query($query,$conn);
}

以下来自手册:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n