请教下提交表单验证重复数据问题

php中文网
发布: 2016-06-20 12:45:31
原创
938人浏览过

<!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')");}?>
登录后复制


打开网页往input里面提交了电话号码,关掉再开再填写电话号码;请问有什么方法禁止重复提交一个号码

采风问卷
采风问卷

采风问卷是一款全新体验的调查问卷、表单、投票、评测的调研平台,新奇的交互形式,漂亮的作品,让客户眼前一亮,让创作者获得更多的回复。

采风问卷 20
查看详情 采风问卷


回复讨论(解决方案)

直接在数据库里面查一遍,有这个号码,就不能插入

直接在数据库里面查一遍,有这个号码,就不能插入

那这个该怎么写

这...
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')");}
登录后复制

就是用户把提交电话的页面关了,再次打开,再次填写,这样数据库中就有重复值了
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号