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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献