Heim >Backend-Entwicklung >PHP-Tutorial >请教下提交表单验证重复数据问题
<!DOCTYPE html><html lang="zh-cmn-Hans"><head><meta charset="utf-8"><title></title><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection"content="telephone=no, email=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="black" /><meta name="format-detection" content="telphone=no, email=no" /><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="HandheldFriendly" content="true"><meta name="MobileOptimized" content="320"><meta name="screen-orientation" content="portrait"><meta name="x5-orientation" content="portrait"><meta name="full-screen" content="yes"><meta name="x5-fullscreen" content="true"><meta name="browsermode" content="application"><meta name="x5-page-mode" content="app"><meta name="msapplication-tap-highlight" content="no"><link href="/cssjs/img/favicon.ico?2015080119" rel="shortcut icon" type="image/x-icon" /><link href="/cssjs/css.css?2015080119" rel="stylesheet" type="text/css" /><script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script></head><body><script type="text/javascript" src="/js/global.js"></script><form id="myform"><input id="url" name='url' type='hidden'><table cellSpacing="3" cellPadding="3" border="0" width="98%"><tr><input id="tel" name="tel" type="text"/><input id="submit" type="button" onclick="formone()" value="提交"/></td></tr></table></form></body></html>
function formone(){var tel=jQuery("#tel").val();var telreg=/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;if(tel==""){alert("请输入您的联系电话!");jQuery("#tel").focus();return false;}else if(!telreg.test(tel)){alert("请输入正确的联系电话!");jQuery("#tel").focus();return false;}else{jQuery.ajax({url:'submit.php',data:{tel:jQuery("#tel").val()},type:'post',dataType:'text',success:function(msg){if(parseInt(msg)!=0){alert("提交成功,点击确定进入抽奖页面...");window.location.href="http://xx.com/sitefiles/services/weixin/lottery/bigwheel.html?lotteryID=1&publishmentSystemID=1&wxOpenID=&_r=6272"}else{alert("提交失败,请直接在线咨询或者拨打000官方电话!");}}})}}
<?phpdefine('INCLUDE_CHECK',1);require_once('connect.php');//连接数据库$tel=stripslashes($_POST['tel']);$time=date('Y年m月d日H时i分s秒',time());if(isset($_POST['tel']) && !empty($_POST['tel'])){$query=mysql_query("insert into tel(tel,time)values('$tel','$time')");}?>
直接在数据库里面查一遍,有这个号码,就不能插入
直接在数据库里面查一遍,有这个号码,就不能插入
那这个该怎么写 这...
mysql_query select 查询电话号码为 xxx的数据,若有返回值,表示有这个号码,提示用户已存在这个号码....否则插入
关掉再开 是什么意思?
if(! mysql_num_rows(mysql_query("select * from tel where tel='$tel'))) { $query=mysql_query("insert into tel(tel,time)values('$tel','$time')");}
关掉再开 是什么意思?
if(! mysql_num_rows(mysql_query("select * from tel where tel='$tel'))) { $query=mysql_query("insert into tel(tel,time)values('$tel','$time')");}就是用户把提交电话的页面关了,再次打开,再次填写,这样数据库中就有重复值了