2015-08-16 37 views
1

它不顯示任何錯誤,並且當我單擊保存按鈕時它不響應。我已經嘗試了PHP插入代碼在其他頁面沒有引導,它的工作原理我想知道爲什麼它不工作在引導模式。Bootstrap模式不響應我的PHP提交表單

這裏是我的HTML代碼:

 <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> 

這我的PHP代碼:

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

您的按鈕提交超出<form></form>標籤。 Kepp在<form></form>標籤內提交表單。

而且還要檢查該行:

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

應該是:

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

宣佈之前,要檢查變量,使用$_POST代替。

您的代碼應該是這樣的:

<?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']; 
    } 
} 
+0

現在作出迴應,但它沒有出現在我的病情的任何錯誤,如果文本框是空白的,它只是刷新。 –

+0

我怎樣才能得到模態內的錯誤信息? –

+0

並不強制關閉模式,如果我收到錯誤 –