请问为什么我的网页按添加删除都没有反应
如题,我用的是PHP和mySQL,是不是要把添加和删除的代码分到另一个文件来写
<body bgcolor="d9dffaa">
<div align="center"><font face="幼圆" size="5" color="#008000">
<b>学生信息录入</b></font></div>
<form name="frm1" method="post" action="AddStu.php" style="margin:0">
<table width="340" align="center">
<tr><td width="168"><span class="STYLE1">根据学号查询学生信息:</span></td>
<td><input name="StuNumber" id="StuNumber" type="text" size="10">
<input type="submit" name="test" class="STYLE1" value="查找"></td></tr>
</table>
</form>
<?php
require "fun.php";
session_start(); //启动SESSION
$number=@$_POST['StuNumber']; //获取学生号
$_SESSION['number']=$number; //讲学生号值传给其他页面
$sql="select*from XSB where XH='$number'"; //查找该生信息
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
if(($number!==NULL)&&(!$row)) //判断学号是否存在
echo "<script>alert('没有该学生信息!')</script>";
$timeTemp=strtotime($row['CSSJ']); //将日期解析为UNIX时间戳
$time=date("Y-n-j",$timeTemp); //用date函数将时间转换为"年-月-日"
?>
<form name="frm2" method="post" style="margin:0" enctype="multipart/form-data">
<table bgcolor="#cccccc" width="430" border="1" align="center" cellpadding="0" cellspacing="0">
<tr><td bgcolor="#ccccccc" width="90"><span class="STYLE1">学号</span></td>
<td><input name="StuNum" type="text" size="35" class="STYLE1" value="<?php echo $row['XH'];?>">
<input name="h_StuNum" type="hidden" value="<?php echo $row['XH'];?>"></td></tr>
<tr><td bgcolor="#CCCCCC" width="90"><span class="STYLE1">姓名:</span></td>
<td><input name="StuName" type="text" size="35" class="STYLE1" value="<?php echo $row['XM'];?>"></td></tr>
<tr><td bgcolor="#CCCCCC"><div class="STYLE1">性别</div></td>
<?php
if($row['XB']===0)
{?>
<td><input type="radio" name="Sex" value="1"><span class="STYLE1">男</span>
<input type="radio" name="Sex" value="0" checked="checked"><span class="STYLE1">女</span></td>
<?php
}
else
{?>
<td><input type="radio" name="Sex" value="1" checked="checked"><span class="STYLE1">男</span>
<input type="radio" name="Sex" value="0"><span class="STYLE1">女</span></td>
<?php
}
?>
</tr>
<tr><td bgcolor="#CCCCCC"><span class="STYLE1">出生日期:</span></td>
<td><input name="Birthday" size="35" type="text" class="STYLE1" value="<?php if($time) echo $time;?>"></td></tr>
<tr><td bgcolor="#CCCCC"><span class="STYLE1">专业</span></td>
<td><input name="Project" size="35" type="text" class="STYLE1" value="<?php echo $row['ZY'];?>"></td></tr>
<tr><td bgcolor="#CCCCCC"><span class="STYLE1">总学分</span></td>
<td><input name="StuZXF" size="35" type="text" class="STYLE1" value="<?php echo $row['ZXF'];?>" readonly></td></tr>
<tr><td bgcolor="#CCCCCC"><span class="STYLE1">备注</span></td>
<td><textarea cols="34" rows="4" name="StuBZ" class="STYLE1"> <?php echo $row['BZ'];?></textarea></td></tr>
<tr><td bgcolor="#CCCCCC" height="150"><span class="STYLE1">学生照片</span></td>
<td align="center">
<?php
if($row['ZP']) //调用showpicture.php 页面用于显示照片,time()函数用于产生一个时间戳,防止服务器读取缓存仲的内容
echo "<img src='showpicture.php?time=".time()."'>";
else
echo "<div class=STYLE1>暂无图片</div>";
?>
<br><input type="file" name="file"></td></tr>
<tr><td align="center" colspan="2" bgcolor="#CCCCCC">
<input name="b" type="submit" value="修改" class="STYLE1">
<input name="b" type="submit" value="添加" class="STYLE1">
<input name="b" type="submit" value="删除" class="STYLE1">
<input name="b" type="button" value="退出" class="STYLE1" onClick="window.location='main.php'"></td></tr>
</table>
</form>
</body>
</html>
<?php
$num=@$_POST['StuNum']; //学号
$XH=@$_POST['h_StuNum']; //表单中原有的隐藏文本中的学号值
$name=@$_POST['StuName']; //姓名
$sex=@$_POST['Sex']; //性别
$birthday=@$_POST['Birthday']; //出生日期
$project=@$_POST['Project']; //专业
$points=@$_POST['StuZXF']; //总学分
$note=@$_POST['StuBZ']; //备注
$tmp_file=@$_FILES["file"]["tmp_name"]; //文件被上传后在服务端储存的临时文件
$handle=@fopen($tmp_file,'r'); //打开文件
$picture=@addslashes(fread($handle,filesiza($tmp_file))); //将图片文件转化为二进制流
$checkbirthday=preg_match('/^\d{4}-(0?\d|1?[012])-(0?\d|[12]\d|3[01])$/',$birthday);
function test($num,$name,$checkbirthday,$tmp_file)
{
if($num==NULL) //判断学号是否为空
{
echo "<script>alert('学号不能为空!');location.href='AddStu.php';</script>";
exit;
}
else if($name==NULL) //判断姓名是否为空
{
echo "<script>alert('姓名不能为空!');location.href='AddStu.php';</script>";
exit;
}
else if($checkbirthday==0) //判断日期是否符合要求
{
echo "<script>alert('日期格式错误!');location.href='AddStu.php';</script>";
exit;
}
{
if($tmp_file)
{
$type=@$_FILES['file']['type'];
$Psize=@$_FILES['file']['size'];
if((($type!="image/gif")&&($type!="image/jpeg")&&($type!="image/pjpeg")&&($type!="image/bmp")))
{
echo "<script>alert('图片格式错误!');location.href='AddStu.php';</script>";
exit;
}
else if($Psize>5000000) //照片大于5M无法上传
{
echo "<script>alert('图片太大,无法上传!');location.href='AddStu.php';</script>";
exit;
}
}
}
}
//单击[修改]按钮
if(@$_POST["b"]=='修改')
{
echo "<script>if(!confirm('确认修改'))return FALSE;</script>";
test($num,$name,$checkbirthday,$tmp_file);
if($num!=$XH)
echo "<script>alert('学号与原数据有异,无法修改!');location.href='AddStu.php';</script>";
else
{
if(!$tmp_file)
{
$update_sql="update XSB set XM='$name',XB=$sex,CSSJ='$birthday',ZY='$project',
BZ='$note' where XH='$XH'";
}
else
{
$update_sql="update XSB set XM='$name',XB=$sex,CSSJ='$birthday',ZY='$project',
BZ='$note',ZP='$picture' where XH='$XH'";
}
$update_result=mysql_query($update_sql);
if(mysql_affected_rows($conn)!=0)
echo "<script>alert('修改成功!');location.href='AddStu.php';</script>";
else
echo "<script>alert('修改失败,请检查输入信息!');location.href='AddStu.php';</script>";
}
}
//单击[添加]按钮
if(@$_POST["b"]=='添加')
{
test($num,$name,$checkbirthday,$tmp_file); //检查表单内容
$s_sql="select XH from XSB where XH='$num'";
$s_result=mysql_query($s_sql);
$s_row=mysql_fetch_array($s_result);
if($s_row)
echo "<script>alert('学号已存在,无法添加!');location.href='AddStu.php';</script>";
else
{
if(!tmp_file)
{
$insert_sql="insert into XSB(XH,XM,XB,CSSJ,ZY,ZXF,BZ)
value('$num','$name','$sex','$birthday','$project',0,'$note')";
}
else
{
$insert_sql="insert into XSB(XH,XM,XB,CSSJ,ZY,ZXF,BZ,ZP)
value('$num','$name','$sex','$birthday','$project',0,'$note','$picture')";
}
$insert_result=mysql_query($insert_sql);
if(mysql_affected_rows($conn)!=0)
echo "<script>alert('添加成功!');location.href='AddStu.php';</script>";
else
echo "<script>alert('添加失败,请检查输入信息!');location.href='AddStu.php';</script>";
}
}
//单击[删除]按钮
if(@$_POST["b"]=='删除')
{
if($num==NULL)
{
echo "<script>alert('请输入要删除的学号!');location.href='AddStu.php';</script>";
}
else
{
$d_sql="select XH from XSB where XH='$num'";
$d_result=mysql_query($d_sql);
$d_row=mysql_fetch_array($d_result);
if(!$d_row)
echo "<script>alert('学号不存在,无法删除!');location.href='AddStu.php';</script>";
else
{
$del_sql="delete from XSB where XH='$num'";
$del_result=mysql_query($del_sql) or die('删除失败!');
if($del_result)
echo "<script>alert('删除学号".$num."成功!');location.href='AddStu.php';</script>";
}
}
}
?>
[解决办法]
代码太多。贴重要部分问吧。
[解决办法]
贴代码最好让你自己也看的懂,不要太高估我们的语文水平,。
[解决办法]
do it like this
if($_POST["b"]=='删除'){ $num=$_POST['StuNum']; //more code....
[解决办法]
贴重要部分!
[解决办法]
enctype="multipart/form-data"????行吗,去掉试试。一步步调试吧。耐心+恒心
------解决方案--------------------
我个人建议啊:下次有代码的时候这样写
这里写代码