如题,我用的是PHP和mySQL, <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>
$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>";
}
}
}
<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>
$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>";
}
}
}
<script language="javascript">
function sub(){
document.form.submit();
}
</script>
<form name="form" action="xxx.php">
<input type="text" name="txt" />
<input type="button" name="submit" onclick="sub()" />
</form>
//提交以后看是否有$_POST['txt']数据
if(isset($_POST)) print_r($_POST);如果没有接收到,则说明你的前端页面有问题。
1、查看你的form中的action指向的是否是你的php接收页面;
2、检查你的Button按钮是否能将表单提交;
3、表单提交最好用Button,可避免刷新重复提交。
我不是很懂代码,你那个script和PHP的代码放在哪里?
2.看看字符串链接,输出
2.看看sql
3.看看返回结果
php放在html前面就行