2015-11-29 202 views
0

我正在嘗試使用Bootstrap對網站進行編碼。我已經使用模態(here)在一個頁面上實現了它,而另一個頁面似乎並未在該頁面上顯示模式(here),但有一個按鈕可以編輯禁止詳細信息,但當單擊編輯按鈕時,它什麼也沒做。Bootstrap Modal顯示在一頁上,但不顯示其他頁面?

此外,我使用jQuery表單提交,這樣我也可以把返回的ID,但是,我堅持我的函數如何返回的ID,因爲使用 get_mysql()->fetch_assoc($result)["id"] 導致500內部服務器錯誤。 代碼可以在下面找到。

ban.php

<div class="modal fade" id="modal" tabindex="-1" role="dialog"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
        <h4 class="modal-title">Edit Ban</h4> 
       </div> 
       <form id="form"> 
        <div class="modal-body"> 
         <div class="form-group"> 
          <input type="text" value="<?php echo $ban["uuid"] ?>" id="uuid" name="uuid" placeholder="UUID" class="form-control"/> 
         </div> 

         <div class="form-group"> 
          <input type="text" value="<?php echo $ban["reason"] ?>" id="reason" name="reason" placeholder="Reason" class="form-control"/> 
         </div> 
        </div> 

        <input type="hidden" id="id" name="id" value="<?php echo $ban["id"] ?>" /> 
        <div class="modal-footer"> 
         <input type="submit" class="btn btn-primary"/> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 

    <script> 
     $(document).ready(function() { 
      $("#form").submit(function(e) { 
       e.preventDefault(); 
       var uuid = $("#uuid").val(); 
       var reason = $("#reason").val(); 
       $.post("add.php", { id: id, uuid: uuid, reason: reason, key: "<?php echo get_key() ?>" }, function(data) { 
        location.href = "ban.php?id=<?php echo data ?>"; 
       }); 
      }); 
     }); 
    </script> 

的index.php

<div class="modal fade" id="modal" tabindex="-1" role="dialog"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
        <h4 class="modal-title">Add Ban</h4> 
       </div> 
       <form id="form"> 
        <div class="modal-body"> 
         <div class="form-group"> 
          <input type="text" value="<?php echo $ban["uuid"] ?>" id="uuid" name="uuid" placeholder="UUID" class="form-control"/> 
         </div> 

         <div class="form-group"> 
          <input type="text" value="<?php echo $ban["reason"] ?>" id="reason" name="reason" placeholder="Reason" class="form-control"/> 
         </div> 
        </div> 
        <div class="modal-footer"> 
         <input type="submit" class="btn btn-primary"/> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <script src="js/bootstrap.min.js"></script> 
    <script> 
     $(document).ready(function() { 
      $("#form").submit(function(e) { 
       e.preventDefault(); 
       var uuid = $("#uuid").val(); 
       var reason = $("#reason").val(); 
       $.post("functions/add.php", { uuid: uuid, reason: reason, key: "<?php echo get_key() ?>" }, function(data) { 
        location.href = "functions/ban.php?id=<?php echo data ?>"; 
       }); 
      }); 
     }); 
    </script> 

api.php

<?php 
define("key", "redacted"); 

function get_mysql() { 
    $mysql = new mysqli("localhost", "redacted", "redacted", "redacted"); 
    if($mysql->connect_error) { 
     die($mysql->connect_error); 
    } 
    return $mysql; 
} 

function add($uuid, $reason) { 
    $date = gmdate("Y-m-d H:i:s"); 
    get_mysql()->query("insert into bans (uuid, date, reason) values ('$uuid', '$date', '$reason')"); 
    $result = get_mysql()->query("select id from bans where uuid = '$uuid' and date = '$date' and reason = '$reason'"); 
    get_mysql()->fetch_array($result); 
    return $result["id"]; 
} 

function update($id, $uuid, $reason) { 
    get_mysql()->query("update bans set uuid = '$uuid', reason = '$reason' where id = $id"); 
} 

function remove($uuid) { 
    get_mysql()->query("delete from bans where uuid = '$uuid'"); 
} 

function remove_by_id($id) { 
    get_mysql()->query("delete from bans where id = $id"); 
} 

function get($uuid) { 
    return get_mysql()->query("select * from bans where uuid = '$uuid'")->fetch_assoc(); 
} 

function get_by_id($id) { 
    return get_mysql()->query("select * from bans where id = $id")->fetch_assoc(); 
} 

function get_bans() { 
    return get_mysql()->query("select * from bans"); 
} 

function login($username, $password) { 
    $password = hash("sha256", $password); 
    return get_mysql()->query("select count(*) from users where username = '$username' and password = '$password'")->num_rows > 0; 
} 

function register($username, $password) { 
    $password = hash("sha256", $password); 
    get_mysql()->query("insert into `users` (`username`, `password`) values ('$username', '$password'"); 
} 

function get_key() { 
    return key; 
} 
?> 
+1

您的第二個鏈接(帶編輯按鈕的鏈接)似乎不會加載引導程序。控制檯拋出'無法加載資源:服務器對'http:// tempzircon.ga/banman/functions/js/bootstrap.min.js'的響應狀態爲404(Not Found)' – stain88

+0

(facepalm)Thanks @ stain88! –

回答

0

我已經找到了答案塔nks到@ stain88。我沒有提供正確的鏈接到bootstrap.min.js(facepalm)

再次感謝@ stain88。

相關問題