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>";
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方