对于我的学校项目,我有以下代码将文件上传到服务器。当上传完成并且文件处理完毕后,页面将重新加载并显示一个模态窗口供用户验证某些数据。问题是,当用户单击提交按钮时,处理表单提交的PHP代码不会被执行。 echo语句打印" no"警报有效,但if语句中没有任何内容执行。
<div class="wrapper">
<form class="form-signin text-center" action="#">
<h2 class="form-signin-heading"><a href="."><img src="img/logo.png" style="width:300px; height:100px;"></a></h2>
<h4>Resume Upload</h4>
<br>
<?php
if (isset($_SESSION["upload-success"]) && !isset($_POST["update"])){
if ($_SESSION["upload-success"] = true){
echo "
<div class='alert alert-info' role='alert' id='verify-banner'><strong>Success!</strong> Resume uploaded successfully.</a></div>
<script type='text/javascript'>
$(document).ready(function() {
$('#edit').modal('show');
});
</script>
";
}else{
echo "<div class='alert alert-danger' role='alert'><strong>Error!</strong> An error occurred while uploading the resume.</div>";
}
unset($_SESSION["upload-success"]);
}
?>
<div class="form-group align-items-center">
<div class="input-group input-file" name="image">
<span class="input-group-btn">
<button class="btn btn-default btn-choose" type="button">Choose</button>
</span>
<input type="text" placeholder='Choose a file...' style="padding-right: 105px;"/>
</div>
<br>
<button class="btn btn-md btn-primary upload" type="submit">Upload</button>
</div>
<div id="progressbar" class="progress progress-striped active" style="display:none;">
<div class="progress-bar" style="width:0%"></div>
</div>
</form>
<div class="modal fade" id="edit">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Verify Resume Data</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="form-group row">
<label class="col-3 col-form-label">First Name</label>
<div class="col-9">
<input class="form-control" type="text" value="<?php echo $_SESSION['fname']?>" name="fname" id="fname">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">Last Name</label>
<div class="col-9">
<input class="form-control" type="text" value="<?php echo $_SESSION['lname']?>" name="lname" id="lname">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">Email Address</label>
<div class="col-9">
<input class="form-control" type="email" value="<?php echo $_SESSION['email']?>" name="email" id="email">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">Phone Number</label>
<div class="col-9">
<input class="form-control" type="text" step="1" value="<?php echo $_SESSION['phone']?>" name="phone" id="phone">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">Notes</label>
<div class="col-9">
<textarea class="form-control" type="text" value="" name="notes" id="notes"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" name="update" id="update" formmethod="post">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if (isset($_POST["update"])){
require_once("db".DIRECTORY_SEPARATOR."db.php");
$userid = $_SESSION["new-user-id"];
$note = $_POST["notes"];
$mydb->query("UPDATE account SET `FirstName`='".$_POST["fname"]."', `LastName`='".$_POST["lname"]."', `EmailAddress`='".$_POST["email"]."', `PhoneNumber`='".$_POST["phone"]."'' WHERE `UserID`='$userid';");
$mydb->query("INSERT INTO resume_notes(`UserID`, `Note`) VALUES('$userid', '$note') ON DUPLICATE KEY UPDATE `Note`='$note';");
//echo "<script>alert('yes');</script>";
unset($_SESSION["fname"]);
unset($_SESSION["lname"]);
unset($_SESSION["email"]);
unset($_SESSION["phone"]);
unset($_SESSION["new-user-id"]);
unset($_POST["update"]);
}else{
//echo "<script>alert('no');</script>";
}
?>