dongzhiyi2006 2016-01-21 14:19
浏览 96
已采纳

在没有按$ _POST按钮的情况下加载页面时获取javascript警报

In my page updel.php I have this code:

$text = $_POST['detail'];
$uren = $_POST['uren'];
if (empty($text )) {
    echo "<script type='text/javascript'>alert(\"Gebeurtenis field must be filled\")</script>";
}
else if (empty($uren)){
    echo "<script type='text/javascript'>alert(\"Uren field must be filled\")</script>";
}

else if (isset($_POST['update'])){
$UpdateQuery = "UPDATE eventcalendar SET Detail='$_POST[detail]', Uren='$_POST[uren]' WHERE ID='$_POST[ID]'";
mysqli_query($login, $UpdateQuery);
}

and in my log.php I have this code:

require_once('../includes/updel.php')

But when I try to load my log.php, without even pressing a button I get the javascript alert of:

Gebeurtenis field must be filled

I tried a lot of things but I don't know what causes this problem. Can anyone help me out?

If needed, this is my code for submitting the form:

while($row = mysqli_fetch_array($myData)){
?>
 <form action="log" method="post" name="Form">
 <tr>
 <input type="hidden" name="ID" value="<?php echo $row['ID']?>">
 <td>
 <?php echo $row['Date']?> 
 </td>
 <td>
 <textarea name="detail" cols="170" rows="3"><?php echo $row['Detail']?></textarea>
 </td>
 <td>
 <input type="number" name="uren" min="1" max="10" value="<?php echo $row['Uren']?>">
 </td>
 <td>
 <input type="submit" name="update" value="Update" class="fa fa-pencil button alterar">
 </td>
 <td>
 <input type="submit" name="delete" value="Delete" class="fa fa-trash button excluir">
 </td>
 </tr>  
 </form>     
  • 写回答

1条回答 默认 最新

  • dsa5233 2016-01-21 14:21
    关注

    You have to check if the form actually has been submitted. To do so use if(isset())

    if(isset($_POST['detail']) && isset($_POST['dren'])){
      $text = $_POST['detail'];
      $uren = $_POST['uren'];
      if (empty($text )) {
          echo "<script type='text/javascript'>alert(\"Gebeurtenis field must be filled\")</script>";
      }
      else if (empty($uren)){
          echo "<script type='text/javascript'>alert(\"Uren field must be filled\")</script>";
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 脱敏项目合作,ner需求合作
  • ¥15 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密