金盛 2014-11-30 14:51 采纳率: 25%
浏览 1995

onsubmit触发事件把表单数据发送到相关php处理问题

问题详情:onsubmit触发事件把表单数据发送到相关php处理但是如何避免数据有问题时也会触发事件呢?

function dosubmit() { window.open('num3.php?cf='+window.form.cf.value+'&cf1='+window.form.cf1.value); }


<?php

require_once('appvars.php');
require_once('connectvars.php');

if(isset($_POST['submit'])){ //第10行

$name=$_POST['name'];
$score=$_POST['score'];
$st=$_FILES['st']['name'];
$st_type=$_FILES['st']['type'];
$st_size=$_FILES['st']['size'];
$output_form=false;

if( empty($name) || empty($score) || empty($st))
{
echo'Something is wrong !
';
$output_form=true;
}
//第20行
else{

if( (($st_type=='image/gif')||($st_type=='image/jpeg')||($st_type=='image/pjeg')||($st_type=='image/png')) && ($st_size >0) && ($st_size <=MAX_FILE_SIZE) )
{

if($_FILES['st']['error']==0){

$target=GW_UPLOADPATH .$st;
//第30行

if(move_uploaded_file($_FILES['st']['tmp_name'],$target)){

$dbc=mysqli_connect(HOST,USER,PASSWORD,NAME);

$st=$_FILES['st']['name'];
$query="INSERT INTO b (date,st,score,name)".
"VALUES(NOW(),'$st','$score','$name')";
//第40行

mysqli_query($dbc,$query)
or die('UU');

echo'You are success to add dates to Mysql '.'<br>';
echo 'Name :'.$name.'<br>';
echo 'Score : '.$score.'<br>';
echo 'Photo :'.'<img src="'.GW_UPLOADPATH.$st.'" >';
                //第50行          
echo'<p><a href="index.php">Back to index page</a></p>';

//clear the score datas
$name="";
$score="";
$st="";

mysqli_close($dbc);

}//if(move_uploaded_f

else
{
echo $_FILES['st']['error'];
echo'
文件没有移动成功 !!';//第60行

}

}//if($_FILES['st']['error']

else
echo'There is something wrong to upload the file ! Plese upload it agian.';

}//if(($st_type=='image/gif'

else echo'

The screen pic must be a GIF,JPEG, or PNG image and the file '.'size must fit '.'(MAX_FILE_SIZE/1024)'.'KB.

';
}//else
                //第70行

//Try to delete the temporary screen shot image file.

@unlink($_FILES['st']['tmp_name']);

}else $output_form=true;

if($output_form){
?>

Your name:
Your score:
Your Photo:
商品交易; 商品互换;

<?php } ?>


  • 写回答

3条回答 默认 最新

  • threenewbee 2014-11-30 18:55
    关注

    在处理函数的开头加上一些前置检查,如果不符合就不再继续执行,直接返回,提示数据不合法就行了呗。

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能