我想过滤此表单中的空输入,因此我输入了一个表单来制作它,我使用了If / else条件。
如果条件不起作用..但是条件正在按我的意愿运作。 有什么问题?
PHP:
if($_GET['rm'] == 'edit'){
$rm_edit_query = $db->query("SELECT * FROM reminders WHERE r_id = '".$_GET['r_id']."'");
$rm_edit_query_fetch = $rm_edit_query->fetch_array(MYSQLI_ASSOC);
if(isset($_POST['save-reminder-changes'])){
if(empty($_POST['rm-name-e']) or empty($_POST['rm-details-e']) or empty($_POST['rm-date-e']) or empty($_POST['rm-time-e'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">يجب كتابة جميع البيانات لحفظ التغييرات.</h3>
<?php
}else{
?>
<style type="text/css">
.rm-table, .main h3, .reminder-submit, .main hr {
display: none;
}
.succeed {
display: block !important;
}
</style>
<?php
$rm_name = $_POST['rm-name-e'];
$rm_details = $_POST['rm-details-e'];
$rm_date = $_POST['rm-date-e'];
$rm_time = $_POST['rm-time-e'];
$rm_insert_query = $db->query("UPDATE reminders SET r_name = '".$rm_name."', r_details = '".$rm_details."', r_date = '".$rm_date."', r_time = '".$rm_time."' WHERE r_id = '".$_GET['r_id']."'");
?>
<h3 dir="rtl" class="succeed" style="margin-top: 30px;text-align: center;font-size: 25px;color: green;">تم حفظ التعديلات. <a href="reminder.php">Show reminders</a></h3>
<?php
exit;
}
}
?>
<style type="text/css">
.rm-table, .main h3, .reminder-submit, .main hr {
display: none;
}
</style>
<form action="reminder.php?rm=edit&r_id=<?php echo $_GET['r_id']; ?>" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date-e" type="date" id="rm" value="<?php echo $rm_edit_query_fetch['r_date'] ?>" /> / <input name="rm-time-e" type="time" id="rm" value="<?php echo $rm_edit_query_fetch['r_time'];?>" />
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name-e" type="text" id="rm" value="<?php echo $rm_edit_query_fetch['r_name'] ?>" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details-e" id="rm-ta"><?php echo $rm_edit_query_fetch['r_details'] ?></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder-changes" type="submit" class="sp-submit" value="Save changes!" /></td>
</tr>
</table>
</form>
<?php
exit;
}
答案 0 :(得分:0)
我使用了This validation tool,似乎问题是在条件中使用or
。您只需将or
替换为||
,如下所示:
<?php
if($_GET['rm'] == 'edit'){
$rm_edit_query = $db->query("SELECT * FROM reminders WHERE r_id = '".$_GET['r_id']."'");
$rm_edit_query_fetch = $rm_edit_query->fetch_array(MYSQLI_ASSOC);
if(isset($_POST['save-reminder-changes'])){
if(empty($_POST['rm-name-e']) || empty($_POST['rm-details-e']) || empty($_POST['rm-date-e']) || empty($_POST['rm-time-e'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">يجب كتابة جميع البيانات لحفظ التغييرات.</h3>
<?php
}
else {
?>
<style type="text/css">
.rm-table, .main h3, .reminder-submit, .main hr {
display: none;
}
.succeed {
display: block !important;
}
</style>
<?php
$rm_name = $_POST['rm-name-e'];
$rm_details = $_POST['rm-details-e'];
$rm_date = $_POST['rm-date-e'];
$rm_time = $_POST['rm-time-e'];
$rm_insert_query = $db->query("UPDATE reminders SET r_name = '".$rm_name."', r_details = '".$rm_details."', r_date = '".$rm_date."', r_time = '".$rm_time."' WHERE r_id = '".$_GET['r_id']."'");
?>
<h3 dir="rtl" class="succeed" style="margin-top: 30px;text-align: center;font-size: 25px;color: green;">تم حفظ التعديلات. <a href="reminder.php">Show reminders</a></h3>
<?php
exit;
}
}
?>
<style type="text/css">
.rm-table, .main h3, .reminder-submit, .main hr {
display: none;
}
</style>
<form action="reminder.php?rm=edit&r_id=<?php echo $_GET['r_id']; ?>" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date-e" type="date" id="rm" value="<?php echo $rm_edit_query_fetch['r_date'] ?>" /> / <input name="rm-time-e" type="time" id="rm" value="<?php echo $rm_edit_query_fetch['r_time'];?>" />
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name-e" type="text" id="rm" value="<?php echo $rm_edit_query_fetch['r_name'] ?>" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details-e" id="rm-ta"><?php echo $rm_edit_query_fetch['r_details'] ?></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder-changes" type="submit" class="sp-submit" value="Save changes!" /></td>
</tr>
</table>
</form>
<?php
exit;
}