<script>
$("#addbutton").click(function(){
$.ajax({
type: "POST",
url: "manage_customer.php?type=add",
data: {
name: $("#name").val(),
password: $("#password").val(),
shortname: $("#shortname").val(),
industry: $("#industry").val(),
contact: $("#contact").val(),
phonenumber: $("#phonenumber").val(),
credit: $("#credit").val(),
email: $("#email").val(),
address: $("#address").val()
},
dataType: "json",
success: function(data){
if (data.success) {
$("#createResult").html(data.msg);
} else {
$("#createResult").html(data.msg);
}
},
error: function(jqXHR){
alert("发生错误:" + jqXHR.status);
},
});
});
</script>
function add() {
//加入客户表
$name=$_POST["name"];
$shortname=$_POST["shortname"];
$password=$_POST["password"];
$industry=$_POST["industry"];
$phonenumber=$_POST["phonenumber"];
$contact=$_POST["contact"];
$credit=$_POST["credit"];
$email=$_POST["email"];
$address=$_POST["address"];
$sql="insert into tb_customer (shortname,email,name,credit,password,industry,phonenumber,contact,address) Values ('$shortname','$email','$name','$credit','$password','$industry','$phonenumber','$contact','$address')";
$result=mysql_query($sql);
//加入用户表
$tag='customer';
$permission='none';
$time=date("Y-m-d H:i:s");
$sql1="insert into tb_user (phonenumber,password,tag,permission,regtime) Values ('$phonenumber','$password','$tag','$permission','$time')";
$result1=mysql_query($sql1);
if($result&&$result1){
echo '{"success":true,"msg":"已成功添加客户!"}';
}
else{
echo '{"success":false,"msg":"客户添加失败!"}';
}
}