我似乎无法找到问题因为我的代码在localhost xampp中工作。但是一旦我上传到实际的服务器,它就无法工作。
没有输出任何错误
当我提交表单时,它会输出加载程序然后消失,并且在<div id="status"></div>
的javascript:
<script>
function _(id){ return document.getElementById(id); }
function submitForm(){
_("bankbtn").disabled = true;
_("status").innerHTML = '<div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"><span class="sr-only">Loading...</span></div></div><br />';
var formdata = new FormData();
formdata.append( "bcountry", _("bcountry").value );
formdata.append( "bname", _("bname").value );
formdata.append( "baname", _("baname").value );
formdata.append( "bno", _("bno").value );
formdata.append( "bswift", _("bswift").value );
var ajax = new XMLHttpRequest();
ajax.open( "POST", "editbank_engine.php" );
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText == "success"){
_("editbank").innerHTML = '<div class="alert alert-success"><h2>Changes has been saved</h2></div>';
} else {
_("status").innerHTML = ajax.responseText;
_("bankbtn").disabled = false;
}
}
}
ajax.send( formdata );
}
</script>
HTML
<div class="modal fade" id="edit" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<form id="editbank" onsubmit="submitForm(); return false;">
<div id="status"></div>
<input class="form-control" type="text" value="<?php echo $bank['bank_country']?>" id="bcountry" placeholder="Bank Country" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_name']?>" id="bname" placeholder="Bank Name" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_accountname']?>" id="baname" placeholder="Bank Account Name" required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_no']?>" id="bno" placeholder="Bank Account No." required=""/><br />
<input class="form-control" type="text" value="<?php echo $bank['bank_swiftcode']?>" id="bswift" placeholder="Bank Swift Code"/><br />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="bankbtn" type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
php
<?php
session_start();
include_once('../php/config.php');
include_once('../php/func.php');
if(
isset($_SESSION['hotel_id']) &&
isset($_POST['bcountry']) &&
isset($_POST['bname']) &&
isset($_POST['baname']) &&
isset($_POST['bno']) &&
isset($_POST['bswift']) &&
!empty($_SESSION['hotel_id']) &&
!empty($_POST['bcountry']) &&
!empty($_POST['bname']) &&
!empty($_POST['baname']) &&
!empty($_POST['bno']) &&
!empty($_POST['bswift'])
){
$update = $dbo->prepare('UPDATE bank_details SET bank_country=:bankcountry, bank_name=:bankname, bank_accountname=:bankaccountname, bank_no=:bankno, bank_swiftcode=:bankswift, active=0, last_updated=NOW() WHERE hid=:hid AND active = 1');
$update->bindParam(':bankcountry', $_POST['bcountry'], PDO::PARAM_STR);
$update->bindParam(':bankname', $_POST['bname'], PDO::PARAM_STR);
$update->bindParam(':bankaccountname', $_POST['baname'], PDO::PARAM_STR);
$update->bindParam(':bankno', $_POST['bno'], PDO::PARAM_STR);
$update->bindParam(':bankswift', $_POST['bswift'], PDO::PARAM_STR);
//$update->bindParam(':active', '0', PDO::PARAM_STR);
$update->bindParam(':hid', $_SESSION['hotel_id'], PDO::PARAM_STR);
$update->execute();
if($update->rowCount() == 1){
echo 'success';
//echo '<div class="alert alert-success"><b>Changes has been saved</b></div>' ;
//mail_log('-User '.$_SESSION['extranet_user'].' has updated his bank details at '.date(time(), 'Y/m/d H:i:s').'');
}else{
echo '<div class="alert alert_danger"><strong>Error has occurred, You can only update once your account has been approved</strong></div>';
//mail_log(' User '.$_SESSION['extranet_user'].' has run into an error via bank details at '.date(time(), 'Y/m/d H:i:s').'');
}
}
?>
答案 0 :(得分:0)
所以我发现了问题。它在我的phpmyadmin(实际服务器)
我正在使用具有id of 0
的测试用户测试我的表单,我只需将其更改为1,由于某种原因它不能设置为0,否则它将无法正常工作