我在PHP中有一个crud系统并创建了一个批准部分。我已经为产品创建了一个批准页面,如果选中此框,则该页面效果很好。但如果不是,并且该人投入表格,则日期仍然存在。如果选中此框,我怎么能只输入日期?
这是表格......
// if the form was submitted
if($_POST){
$product->reviewed = $_POST['reviewed'];
$product->review_date = $_POST['review_date'];
// set product property values
// update the product
if($product->approve()){
echo "<div class='alert alert-success alert-dismissable'>";
echo "Product approvals were set.";
echo "</div>";
}
// if unable to update the product, tell the user
else{
echo "<div class='alert alert-danger alert-dismissable'>";
echo "Unable to approve product.";
echo "</div>";
}
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"] . "?id={$id}");?>" method="post">
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>Name</td>
<td><?php echo $product->name; ?></td>
</tr>
<tr>
<td>Review</td>
<td><?php
if (is_null($product->reviewed)){
?>
<div id="ck-button"><label><input type="checkbox" name="reviewed" value="<?php echo $userRow['user_name'];?>" id="checkbox"/><span>Approve</span>
<input type='hidden' name='review_date' class='form-control' value="<?php echo date("Y-m-d h:i:sa"); ?>"/>
</div> </label>
<?php ;
}elseif (isset($product->reviewed)){
echo "<div id='approved-button'>" . $product->reviewed . ", " . $product->review_date . "</div>";
}
?>
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">Set Approvals</button>
</td>
</tr>
</table>
</form>
以下是Product类
中的函数 //approval for products
function approve(){
$query = "UPDATE
" . $this->table_name . "
SET
reviewed = :reviewed,
review_date = :review_date
WHERE
id = :id";
$stmt = $this->conn->prepare($query);
$this->id=htmlspecialchars(strip_tags($this->id));
$this->reviewed=htmlspecialchars(strip_tags($this->reviewed));
$this->review_date=htmlspecialchars(strip_tags($this->review_date));
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(":reviewed", $this->reviewed);
$stmt->bindParam(":review_date", $this->review_date);
// execute the query
if($stmt->execute()){
return true;
}
return false;
}
答案 0 :(得分:1)
检查是否已选中复选框元素&#39;在PHP中,您执行以下操作:
if(isset($_POST['myCheckbox'])) { ... }
相反,你有
if($_POST) { ... }
如果我正确理解你的问题,那么你的问题似乎是什么。