请假下各位php表单问题

WBOY
Release: 2016-06-23 13:26:28
Original
948 people have browsed it

PHP代码submit.php
这个代码存在的问题,只要刷新submit.php这个页面就会不断往数据库中添加空白数据,请问(我是小白太高级的目前还不懂)该如何增加对字段验证或者增加验证码功能

<?php/** * @处理表单提交数据*/define('INCLUDE_CHECK',1);require_once('connect.php');$name=stripslashes($_POST['name']);$tel=stripslashes($_POST['tel']);$ask=stripslashes($_POST['ask']);$des=stripslashes($_POST['des']);$time=date('Y年m月d日H时i分s秒',time());$url=stripslashes($_POST['url']);$query=mysql_query("insert into say(name,tel,ask,des,time,url)values('$name','$tel','$ask','$des','$time','$url')");?>
Copy after login


回复讨论(解决方案)

$query=mysql_query("insert into say(name,tel,ask,des,time,url)values('$name','$tel','$ask','$des','$time','$url')");这一段代码放在一个if条件判断里面。 在判断中进行对应的条件判断,比如$name != "" 这样。

<?php/** * @处理表单提交数据*/define('INCLUDE_CHECK',1);require_once('connect.php');if($_POST) {  $name=stripslashes($_POST['name']);  $tel=stripslashes($_POST['tel']);  $ask=stripslashes($_POST['ask']);  $des=stripslashes($_POST['des']);  $time=date('Y年m月d日H时i分s秒',time());   $url=stripslashes($_POST['url']);  $query=mysql_query("insert into say(name,tel,ask,des,time,url)values('$name','$tel','$ask','$des','$time','$url')");}?>
Copy after login

如果有post数据就执行数据库插入,否则不执行

if(isset($_POST['name']) && !empty($_POST['name'])){	$query=mysql_query("insert into say(name,tel,ask,des,time,url)values('$name','$tel','$ask','$des','$time','$url')");}
Copy after login

在前台表单的submit按钮上加一个value
后台判断$_post['submit']是否有值

if($_post['submit']){表单提交操作}else{不是提交操作}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template