我尝试提交表单,但不发送表单。如果我尝试打印POST数组,它只是空的。
这是我的表格:
<?php
print_r($_POST);
require('includes/config.php');
require('includes/auth_admin.php');
$title = "New Block Day";
require ('includes/header.php');
//if form has been submitted process it
if(isset($_POST['submit'])){
if(empty($_POST['name'])){
$error[] = 'Please Enter a name.';
}
$date = $_POST['date'];
$result = mysqli_query($con, "select name from official_holiday where date = $date");
while ($row = mysqli_fetch_assoc($result)) {
$check[] = $row;
}
if(empty($_POST['date'])){
$error[] = 'Please Enter a date.';
}elseif(!empty($_POST['date'])){
$error[] = 'Already block date on that day.';
}
$new_date = $_POST['date'];
$new_name = $_POST['name'];
$query = sprintf("INSERT INTO official_holiday (name, date) VALUES ('%s', '%s')",
mysql_real_escape_string($new_name),
mysql_real_escape_string($new_date));
$result = mysqli_query($con, $query);
header("Location:new_block.php?id=$id&changes=successful");
}else{
//header('0');
//exit;
}
?>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
<form action="new_block.php" method="post" role="form" >
<h3><?php echo $title ?></h3>
<p><a href='block_days.php'>Back</a></p>
<?php
if(isset($_GET['changes']) && $_GET['changes'] = 'successful'){
echo '<h4>Changes successful.</h4>';
}
?>
<hr>
<label for="name">Name</label>
<div class="form-group">
<input type="text" required name="name" id="name" class="form-control" value="<?php if(isset($error)){ echo $_POST['name']; } ?>" tabindex="3">
</div>
<div class="form-group">
<label for="datepicker">Date</label>
<div class="input-group input-append date">
<input type="text" class="form-control" id="datepicker" name="date" placeholder="Date" value="<?php if(isset($error)){ echo $_POST['date']; } ?>">
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar">
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" id="name" value="submit" class="btn btn-info btn-block" tabindex="5">
</div>
</form>
</div>
</div>
</div>
<?php
require('includes/footer.php');
?>
为什么PHP不发送任何内容?
编辑:我添加了完整的代码,但我可以添加的内容不多。
答案 0 :(得分:0)
请先评论您的重定向:
// header("Location:.."
)