大家好我正在创建“结算地址”“投放地址”表单。 当有人填写账单地址详细信息并且交付相同时,我想保存一个人在框中打勾以填充详细信息。
我尝试使用javascript和php验证它,它们位于表单上方的同一页面上(不在head标签中),没有任何乐趣。
*脚本更新数据库*,ajax没有得到来自php的回声,这是我无法弄清楚的另一件事。所以我有几个问题,不知道,也许有些东西干扰了网页。
我只是想知道它应该如何运作。
当我点击“提交”时--AJAX将变量发送给PHP,然后PHP更新数据库并回显字符串,然后传回给AJAX。但是AJAX看不到它,我在AJAX代码中显示的错误字符串没有显示,唯一显示的是“发生了一些错误”(我甚至在某个阶段将其更改为“成功更新”导致数据库更新:))
非常感谢任何帮助
页面名为myaccount.php
<?php
// AJAX CALLS THIS CODE TO EXECUTE
if(isset($_POST['p'])||isset($_POST['a1'])||isset($_POST['a2'])||isset($_POST['c'])||isset($_POST['co'])||isset($_POST['con'])||isset($_POST['da1'])||isset($_POST['da2'])||isset($_POST['dc'])||isset($_POST['dco'])||isset($_POST['addcheckbox'])){
require_once('./includes/mysql_connect.php');
$p = mysql_real_escape_string(trim($_POST['p']));
$a1 = mysql_real_escape_string(trim($_POST['a1']));
$a2 = mysql_real_escape_string(trim($_POST['a2']));
$c = mysql_real_escape_string(trim($_POST['c']));
$co = mysql_real_escape_string(trim($_POST['co']));
$da1 = mysql_real_escape_string(trim($_POST['da1']));
$da2 = mysql_real_escape_string(trim($_POST['da2']));
$dc = mysql_real_escape_string(trim($_POST['dc']));
$dco = mysql_real_escape_string(trim($_POST['dco']));
if(isset($_POST['addcheckbox'])=='ticked'){
$da1 = mysql_real_escape_string(trim($_POST['a1']));
$da2 = mysql_real_escape_string(trim($_POST['a2']));
$dc = mysql_real_escape_string(trim($_POST['c']));
$dco = mysql_real_escape_string(trim($_POST['co']));
}
$sql = "UPDATE customers SET address_1='$a1', address_2='$a2', phone='$p', city='$c', county='$co', country='$con', del_ad_1='$da1', del_ad_2='$da2', del_city='$dc', del_county='$dco' WHERE id_cust='$id'";
$query = mysql_query($sql);
if(!$query){
echo 'success';
exit();
}else{
echo 'not_updated';
exit();
}
}
?>
这是javascript
<script type="text/javascript" language="javascript">
function changeaddress(){
var p = _("phone").value;
var a1 = _("address_1").value;
var a2 = _("address_2").value;
var c = _("city").value;
var co = _("county").value;
var con = _("country").value;
var da1 = _("deladdress_1").value;
var da2 = _("deladdress_2").value;
var dc = _("delcity").value;
var dco = _("delcounty").value;
//checkbox
if(document.getElementsById("addcheckbox").checked){
var da1 = a1;
var da2 = a2;
var dc = c;
var dco = co;
}else{
var da1 = _("deladdress_1").value;
var da2 = _("deladdress_2").value;
var dc = _("delcity").value;
var dco = _("delcounty").value;}
//ajax call
if((p!=""||p=="") && (a1!="") && (a2!=""||a2=="") && (c!="") && (co!="")){
//_("changeaddbtn").style.display = "none";
_("status").innerHTML = 'updating your details ...';
var ajax = ajaxObj("POST", "/myaccount.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
var response = ajax.responseText;
if(response == 'success'){
_("changeaddressform").innerHTML = '<h3>Address is updated, check the first tab!!</p>';
} else if (response == 'not_updated'){
_("status").innerHTML = "An error occured , the details were not updated!";
} else {
_("status").innerHTML = "Some error occured!";
}
}else{
_("status").innerHTML = "loading...";}
}
ajax.send("p="+p+"&a1="+a1+"&a2="+a2+"&c="+c+"&co="+co+"&da1="+da1+"&da2="+da2+"&dc="+dc+"&dco="+dco)
;
}
}
</script>
这是Billingpart
Address*
--------------------
<input class="input_field" type="text" size="40" id="address_1" name="address_1" value="<?php echo ''.$get_row['address_1'].''; ?>"/>
Address
----------------------
<input class="input_field" type="text" size="40" id="address_2" name="address_2" value="<?php echo ''.$get_row['address_2'].' '; ?>"/>
City/Town*
<input class="input_field" type="text" size="40" id="city" name="city" value="<?php echo ''.$get_row['city'].' '; ?>"/>
County*
-----------------------
<input class="input_field" type="text" size="40" id="county" name="county" value="<?php echo ''.$get_row['county'].' '; ?>"/>
<p><button id="changeaddbtn" class="submit_btn" onclick="changeaddress()" >Submit Changes</button>
投放
<input type="checkbox" name="addcheckbox" id="addcheckbox" value="ticked" /> Same as billing </p>
“/&GT;
Address
-------------------------------
<input class="input_field" type="text" size="40" id="deladdress_2" value="<?php echo ''.$get_row['del_ad_2'].' '; ?>"/>
City/Town*
-------------------------
<input class="input_field" type="text" size="40" id="delcity" value="<?php echo ''.$get_row['del_city'].' '; ?>"/>
County*
-------------
<input class="input_field" type="text" size="40" id="delcounty" value="<?php echo ''.$get_row['del_county'].' '; ?>"/>
-----------------------------------------------
<p><button id="changeaddbtn" class="submit_btn" onclick="changeaddress()" >Submit Changes</button></p>
<p id="status"></p>
<p id="status1"></p>
<p id="status2"></p>
<p id="status3"></p>
答案 0 :(得分:0)
这是我的回答
function checkCheckbox(){
if (_("checkbox1").checked == true){
_("deladdress_1").value = _("address_1").value;
_("deladdress_2").value = _("address_2").value;
_("delcity").value = _("city").value;
_("delcounty").value = _("county").value;
_("delcountry").value = _("country").value;
}else{
_("deladdress_1").value = "";
_("deladdress_2").value = "";
_("delcity").value = "";
_("delcounty").value = "";
_("delcountry").value = "";
}
}