
else if($action == 'add'){
$user_id = htmlspecialchars($user_id);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="40" align="right">新增收货地址:</td>
<td><span style="color:#f90;">电话号码、手机号选填一项,其余均为必填项</span></td>
</tr>
<tr>
<td height="40" align="right"> 所在地区:</td>
<td><select name="live_prov" id="live_prov" onchange="SelProv(this.value,'live');">
<option value="-1">请选择</option>
<?
$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='area' AND level=0 ORDER BY orderid ASC, datavalue ASC");
while($data = $dosql->GetArray())
{
echo '<option value="'.$data['datavalue'].'">'.$data['dataname'].'</option>';
}
?>
</select>
<select name="live_city" id="live_city" onchange="SelCity(this.value,'live');">
<option value="-1">--</option>
</select>
<select name="live_country" id="live_country">
<option value="-1">--</option>
</select></td>
</tr>
<tr>
<td height="40" align="right">详细地址:</td>
<td><textarea name="address_detail" id="address_detail" class="class_areatext"></textarea></td>
</tr>
<tr>
<td height="40" align="right">邮政编码:</td>
<td><input type="text" name="postcard" id="postcard" class="class_input" /></td>
</tr>
<tr>
<td height="40" align="right">收货人姓名:</td>
<td><input type="text" name="consignee_name" id="consignee_name" class="class_input" /></td>
</tr>
<tr>
<td height="40" align="right">手机号码:</td>
<td><input type="text" name="mobile" id="mobile" class="class_input" placeholder="中国大陆 +86" /> </td>
</tr>
<tr>
<td height="40" align="right">固定电话:</td>
<td><input type="text" name="telephone" id="telephone" class="class_input" placeholder="中国大陆 +86" /></td>
</tr>
<tr>
<td height="40" align="right"></td>
<td height="40" align="left"><input type="checkbox" name="is_default" id="is_default" value="1" checked="checked" /><label for="is_default" style="color:#f90;">设为默认收货地址</label></td>
</tr>
<!-- <tr>
<td height="40" align="right"></td>
<td height="40" align="left"><input type="checkbox" name="is_default" id="is_default" value="1" <?/* if($row['is_default'] == 1){*/?>checked="checked"<?/* }*/?> /><label for="is_default" style="color:#f90;">设为默认收货地址</label></td>
</tr> -->
<tr>
<td height="40" align="right"></td>
<td height="40"><input type="submit" class="btn" value="保 存" onClick="actionAddress('addsave',<?php echo $user_id;?>)" /></td>
</tr>
</table>
<script>
function SelProv(val,input)
{
$("#"+input+"_country").html("<option>--</option>");
$.ajax({
url : "ajax_do.php?action=getarea&datagroup=area&level=1&areaval="+val,
type:'get',
dataType:'html',
success:function(data){
$("#"+input+"_city").html(data);
}
});
}
function SelCity(val,input)
{
$.ajax({
url : "ajax_do.php?action=getarea&datagroup=area&level=2&areaval="+val,
type:'get',
dataType:'html',
success:function(data){
$("#"+input+"_country").html(data);
}
});
}
</script>
<?
}else if($action == 'addsave'){
//HTML转义变量
$live_prov = htmlspecialchars($live_prov);
$live_city = htmlspecialchars($live_city);
$live_country = htmlspecialchars($live_country);
$address = htmlspecialchars($address);
$consignee_name = htmlspecialchars($consignee_name);
$postcard = htmlspecialchars($postcard);
$mobile = htmlspecialchars($mobile);
$telephone = htmlspecialchars($telephone);
@$is_default = htmlspecialchars($is_default);
$user_id = htmlspecialchars($user_id);
$addtime = time();
$sql = "INSERT INTO `#@__address` (user_id,username,mobile,telephone,prov_id,city_id,country_id,address,postcard,is_default,addtime) VALUES ('$user_id','$consignee_name','$mobile','$telephone','$live_prov','$live_city','$live_country','$address','$postcard','$is_default','$addtime')";
if($dosql->ExecNoneQuery($sql)){
$info = array();
$info['status'] = 'y';
$info['info'] = '新增收获地址成功!';
echo json_encode($info);
}
exit();
}
上面的是表单代码下面的是保存数据到数据库代码
else if($action == 'edit'){
//HTML转义变量
$live_prov = htmlspecialchars($live_prov);
$live_city = htmlspecialchars($live_city);
$live_country = htmlspecialchars($live_country);
$address = htmlspecialchars($address);
$consignee_name = htmlspecialchars($consignee_name);
$postcard = htmlspecialchars($postcard);
$mobile = htmlspecialchars($mobile);
$telephone = htmlspecialchars($telephone);
@$is_default = htmlspecialchars($is_default);
$user_id = htmlspecialchars($user_id);
$updatetime = time();
$id = htmlspecialchars($id);
$r = $dosql->GetOne("SELECT * FROM `#@__address` WHERE user_id='$user_id' AND is_default=1");
if(isset($r) && is_array($r)){
if($is_default == 1){
$dosql->ExecNoneQuery("UPDATE `#@__address` set is_default=0 WHERE user_id='$user_id' AND id=".$r['id']);
$sql = "UPDATE `#@__address` SET username='$consignee_name', mobile='$mobile', telephone='$telephone', prov_id='$live_prov', city_id='$live_city', country_id='$live_country', address='$address', postcard='$postcard', is_default='$is_default', updatetime='$updatetime' WHERE id = '$id'";
if($dosql->ExecNoneQuery($sql)){
$info = array();
$info['status'] = 'y';
$info['info'] = '更新地址成功!';
echo json_encode($info);
}
}else{
$sql = "UPDATE `#@__address` SET username='$consignee_name', mobile='$mobile', telephone='$telephone', prov_id='$live_prov', city_id='$live_city', country_id='$live_country', address='$address', postcard='$postcard', is_default='$is_default', updatetime='$updatetime' WHERE id = '$id'";
if($dosql->ExecNoneQuery($sql)){
$info = array();
$info['status'] = 'y';
$info['info'] = '更新地址成功!';
echo json_encode($info);
}
}
}else{
$sql = "UPDATE `#@__address` SET username='$consignee_name', mobile='$mobile', telephone='$telephone', prov_id='$live_prov', city_id='$live_city', country_id='$live_country', address='$address', postcard='$postcard', is_default='$is_default', updatetime='$updatetime' WHERE id = '$id'";
if($dosql->ExecNoneQuery($sql)){
$info = array();
$info['status'] = 'y';
$info['info'] = '更新地址成功!';
echo json_encode($info);
}
}
exit();
}else{
exit('Request Error!');
}
?>
最佳答案
