duanfei7508 2015-08-16 05:45
浏览 9

too long

It doesn't show any error and it doesn't respond when I click Save button. I've tried the PHP insert code in other page without bootstrap and it works I wonder why it's not working in bootstrap modal.

Here's my HTML code:

        <div class="modal-content">
                <div class="modal-header">
                    <h4>Add Topic</h4>
                </div>

                <div class="modal-body">
                    <form method="POST" action="index.php" role="form">
                          <div class="form-group">
                            <label for="cCategory">Category</label>
                            <input type="text" class="form-control" id="cCategory" name="category" value="<?php if (!empty($categ)) { echo $categ; }  ?>">
                          </div>        

                        <div class="form-group">
                            <label for="cTitle">Title</label>
                            <input type="text" class="form-control" id="cTitle" name="topicTitle" value="<?php if (!empty($topicTitle)) { echo $topicTitle; }  ?>">
                          </div>

                          <div class="form-group">
                            <label for="cDesc">Description</label>
                            <textarea class="form-control custom-control" rows="3" style="resize:none" name="desc" value="<?php if (!empty($desc)) { echo $desc; }  ?>"> </textarea>
                          </div>

                          <div class="form-group">
                            <label for="cDesc">Created By</label>
                            <input type="text" class="form-control" id="cDesc" name="createdby" value="<?php if (!empty($created)) { echo $created; }  ?>">
                          </div>
                        </form> 
                </div>
                <div class="modal-footer">
                  <button type="submit" name="submit" class="btn btn-primary">Save changes</button>
                </div>

        </div>

And this my PHP code:

    if(!empty($desc) && !empty($categ) && !empty($topicTitle) && !empty($topicTitle) && !empty($created))   {

        if($insert = $db->query("
             INSERT INTO pncontent (category, title, description, createdby, dateadded)
             VALUES ('$categ', '$topicTitle', '$desc', '$created', NOW() )
            ")) {
                echo $db->affected_rows, " Topic Save!";
            }else {
                echo "Failed to Save";
            }

        }else {
            echo "<p>All Fields are required</p>";
                    $desc = $_POST['desc'];
                    $categ = $_POST['category'];
                    $topicTitle = $_POST['topicTitle'];
                    $created = $_POST['createdby'];
        }
    }
  • 写回答

1条回答 默认 最新

  • douan7529 2015-08-16 06:06
    关注

    Your button Submit is out of <form></form> tag. Kepp it inside <form></form> tag to submit the form.

    And also check this line:

     if(!empty($desc) && !empty($categ) && !empty($topicTitle) && !empty($topicTitle) && !empty($created)) 
    

    Should be:

    if(!empty($_POST['desc']) && !empty($_POST['category']) && !empty($_POST['topicTitle']) && !empty($_POST['createdby'])) 
    

    You are checking variables before declaring it, use $_POST instead.

    Your code should look like this:

    <?php
    
            if(!empty($_POST['desc']) && !empty($_POST['category']) && !empty($_POST['topicTitle']) && !empty($_POST['createdby']))   {
    
    
            $desc1 = $_POST['desc'];
            $categ1 = $_POST['category'];
            $topicTitle1 = $_POST['topicTitle'];
            $created1 = $_POST['createdby'];
    
            if($insert = $db->query("
             INSERT INTO pncontent (category, title, description, createdby, dateadded)
             VALUES ('$categ1', '$topicTitle1', '$desc1', '$created1', NOW() )
            ")) {
                echo $db->affected_rows, " Topic Save!";
            }else {
                echo "Failed to Save";
            }
    
        }else {
            echo "<p>All Fields are required</p>";
                    $desc = $_POST['desc'];
                    $categ = $_POST['category'];
                    $topicTitle = $_POST['topicTitle'];
                    $created = $_POST['createdby'];
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。