duanba5777 2016-07-13 01:15
浏览 97
已采纳

成功发布新闻后显示引导警报框

This is what i want to do. Everytime when the admin successfully posted a news i want the div success alert to popup and dissappear after 3 seconds. I want to put it after the text "Add News" As you can see in picture. Can someone give me a clue on how to do this?

Here is the sample picture of my work. enter image description here

here is my php code for adding the news.

  <?php
    include_once('connection.php');
    session_start();
   $username = ucfirst($_SESSION['username']);

  if(isset($_POST['submit'])){

    $title = $_POST['title'];
    $date = $_POST['date'];
    $content = $_POST['content'];
    $file=$_FILES['image']['tmp_name'];
    $image= @addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name= addslashes($_FILES['image']['name']);
    move_uploaded_file($_FILES["image"]["tmp_name"],"img/" . $_FILES["image"]["name"]);
    $newsimage="img/" . $_FILES["image"]["name"];



    $sql ="INSERT into news (news_title, news_date, news_content, news_image) VALUES ('$title', '$date', '$content', '$newsimage')";
    mysqli_query($con, $sql);



  }
  ?>

here is my form where the alert box is in.

 <div id="page-wrapper">

            <div class="container-fluid">

                  <a class='btn btn-info' href ="news.php" style="margin-bottom:25px; float:right;" ><span class="glyphicon glyphicon-search"></span> View all news</a>


            <form method="post" action ="addnews.php" enctype="multipart/form-data">

             <h4>Add News</h4>

             <div class="alert alert-success" id="success-alert">
              <strong>Successfully posted!</strong>
             </div>

                <div class="form-group">
                       <label for="title">News Title</label>
                        <input type="text" name="title" class="form-control title" id="title" placeholder="News Title" required >
                </div>  

              <div class="form-group">
               <label for="title">Date</label>
                   <input type="text" name="date" class="form-control date" id="date" placeholder="Date" required >  
                </div>

                <div class="form-group">
                      <label for="content">News Content</label>
                     <textarea class="form-control content" name="content" rows="5" id="content" required></textarea>
                </div>    


                      <img id="blah" src="" alt="image here" width="200px" height="140px"/>
                       <input id="image" name="image" class="fileupload" type="file" accept="image/*"/>
                     <button type="submit" name="submit" id="postnews" class='btn btn-info '>Post news</button>
              </form>




        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
  • 写回答

3条回答 默认 最新

  • draw62188 2016-07-13 01:27
    关注

    You could Php session to display alert box on form submission like:

    <?php
    if(isset($_SESSION['form_submit'])) {
     echo '<div class="alert alert-success alert-dismissable" id="success-alert">';
              echo '<strong>Successfully posted!</strong>';
             echo '</div>';
     unset($_SESSION['form_submit']);
    }
    ?>
    

    You have set this session variable on form submission :- $_SESSION['form_submit']=true

    to automaticaly hide this alert box you could use this javascript code

    $(".alert-dismissable").fadeTo(2000, 500).slideUp(500, function(){
     $(".alert-dismissable").alert('close');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: