您的位置:首页 > 其它

添加数据和检查数据

2015-11-25 14:22 99 查看
js验证

<script language="javascript">
function trim(str) {
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function shoppk() {
if (trim(ClientName.value) == "") {
alert("请填写姓名!");
return false;
}
if (!ClientName.value.match(/^[\u4e00-\u9fa5]{2,4}\s*$/)) {
alert('输入的收货人姓名不合法!');
return false;
}
if (trim(ClientPhone.value) == "" || ClientPhone.value.length != 11) {
alert("请正确填写手机号!");
return false;
}
if (!ClientPhone.value.match(/^0*(13|15|18)\d{9}$/)) {
alert('输入的手机号码不合法!');
return false;
}
if (Province.value == "" || City.value == "" || Area.value == "") {
alert("请选择省市县!");
return false;
}
if (trim(ClientAddress.value) == "") {
alert("请填写详细收货地址!");
return false;
}
if (ClientAddress.value.length >25) {
alert('输入的详细地址长度过长!');
return false;
}
}

</script>


PHP添加

<?php
include("conn.php");
header("Content-type: text/html; charset=utf-8");
$consignee=trim($_POST['ClientName']);
$ClientAddress=$_POST['ClientAddress'];
$tel=$_POST['ClientPhone'];
$username=$_POST['ClientId'];
$title=$_POST['Sku'];
$Province=$_POST['Province'];
$City=$_POST['City'];
$Area=$_POST['Area'];
date_default_timezone_set('Asia/Shanghai');
$time=date('Y-m-d H:i:s',time());
$address=$Province.$City.$Area.$ClientAddress;
if(!empty($consignee) and !empty($tel) and!empty($address)) {
$check="select * from dede_shops_userinfo where consignee='".$consignee."' or tel='".$tel."'";       //检查填写的是否存在于数据库 用户名或手机号是否存在
$result=mysql_query($check);
$info=mysql_fetch_row($result);
if($info==0 or $info==''){                                                                          //如果数据库里没有此数据则运行
$sql="insert into dede_shops_userinfo(title,username,oid,consignee,address,tel,time,state)"."values('$title','$username','','$consignee','$address','$tel','$time','')";
mysql_query($sql);
echo"<script>window.location.href='register_ok.php' </script>";
}
else{echo "<script> alert('您已领取过,请把机会留给其他人,谢谢合作!');window.location.href='javascript:history.go(-1)';</script>";}
}
else{echo "<script> alert('您填写的信息有误!');window.location.href='javascript:history.go(-1)';</script>";}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: