Heim > Artikel > Backend-Entwicklung > php过滤空值的有关问题
php过滤空值的问题
这个要死的POST,已经忽视了IF判断直接把空值写入数据库了
PHP接收端:
<br />if($_GET['do'] =='add'){<br />if(!isset($_POST['porgnum']) && empty($_POST['porgnum'])){<br />echo '未填写登录名!';<br />}else if(!isset($_POST['porgname']) && empty($_POST['porgname'])){<br />echo '未填写昵称!';<br />}else if(!isset($_POST['ppasswd']) && empty($_POST['ppasswd'])){<br />echo '未填写密码!';<br />}else{<br />$orgid =$_POST['porgnum'];<br />$orgname =$_POST['porgname'];<br />$passwd =$_POST['ppasswd'];<br />$author =$_POST['pauthor'];<br />$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWD);<br />mysql_select_db(DB_NAME,$con);<br />mysql_query("SET NAMES 'utf8'");<br />mysql_query("SET CHARACTER_SET_CLIENT=utf8");<br />mysql_query("SET CHARACTER_SET_RESULTS=utf8");<br />if(!mysql_query("INSERT INTO `".DB_PRE."menber` (orgnum, orgname, passwd, power) VALUES ('$orgid', '$orgname', '$passwd', '$author')")){<br />die('错误!代码:' .mysql_error());<br />}else{<br />echo '注册成功!';<br />};<br />mysql_close($con);<br />};<br />
<br /><tr><td>登录名</td><td><input type="text" id="orgnum" /></td></tr><br /><tr><td>名称</td><td><input type="text" id="orgname" /></td></tr><br /><tr><td>新密码</td><td><input type="text" id="passwd" /></td></tr><br /><tr><td>12</td><td><select id="author"><option value="v">123</option></select></td></tr><br /><tr><td colspan="2"><input type="button" value="提交" onclick="new_org();" /></td></tr><br /><tr><td colspan="2"><div class="admin_display"></div></td></tr><br />
<br />function new_org(){<br />var orgnum = j('#orgnum').val();<br />var orgname = j('#orgname').val();<br />var passwd = j('#passwd').val();<br />var author = j('#author').val();<br />j.ajax({<br />type:"POST",<br />url:"action.php?do=add",<br />data:{<br />porgnum:orgnum,<br />porgname:orgname,<br />ppasswd:passwd,<br />pauthor:author<br />},<br />dataType:"html",<br />cache:false,<br />async:false,<br />error:function(){<br />alert("发送失败!");<br />},<br />success:function(msg){<br />j('.admin_display').html(msg);<br />alert(orgnum);<br />}<br />});<br />};<br />