2014-03-25 2 views
0

나는 체크 박스의 값을 얻는 방법을 알아 내려고하고있다.이 변수를 SQL db의 id라는 변수에 제출한다. 다음은 체크 박스의 값을 변수에 넣기

내 현재 코드입니다 :

- Index.php는

<?php 

    $sql = "SELECT * FROM `file`"; 

     if (!$result = $db->query($sql)){ 
      die('There was an error running the query [' . $db->error . ']'); 
      } 
    ?> 

    <form method="post"> 

    <a href="includes/AED/file_add.php" data-toggle="modal" data-target="#NEW"><button class="btn btn-success">New</button></a> 
    <a href="includes/AED/file_edit.php" data-toggle="modal" data-target="#EDIT"><button type="submit" class="btn btn-warning">Edit</button></a> 
    <a href="includes/AED/file_delete.php" data-toggle="modal" data-target="#DELETE"><button class="btn btn-danger">Delete</button></a> 

    <table class="table table-condensed"> 

     <thead> 
     <th>#</th> 
     <th>Name</th> 
     <th>Category</th> 
     <th>Date</th> 
     </thead> 

     <tbody> 

     <?php while($row = $result->fetch_assoc()){ ?> 

     <td><input type="checkbox" name="id_grab" value="<?php echo $row['file_id']; ?>"></td> 
     <td><a href="simple/files/<?php echo $row['file_location']; ?>"><?php echo $row['file_name']; ?></a></td> 
     <td><?php echo $row['file_category']; ?></td> 
     <td><?php echo date('d-m-y', strtotime($row['file_date'])); ?></td> 

     </tbody> 

    <?php } ?> 
    </table> 

    </form> 

- file_edit.php

<?php include('../db_connect.php') ; 

$id=isset($_POST['id_grab']); 

    $sql = "SELECT * FROM `file` WHERE file_id = $id"; 

     if (!$result = $db->query($sql)){ 
      die('There was an error running the query [' . $db->error . ']'); 
      } 

     $row = $result->fetch_assoc(); 
?> 



<div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;  </button> 
    <h4 class="modal-title" id="myModalLabel">Edit Invoice/Receipt</h4> 
    </div> 
    <div class="modal-body"> 

    <form action="../includes/file_update.php" method="post" role="form" enctype="multipart/form-data"> 

     <div class="form-group"> 
      <label for="File_Name">Name</label> 
      <input type="text" name="file_name" class="form-control" id="file_name" value="<?php echo $row['file_name']; ?>"> 
     </div> 

     <div class="form-group"> 
      <lable for="File_Category">Category</label> 
      <input type="text" name="file_category" class="form-control" id="file_category" placeholder="Financial"> 
     </div> 

     <div class="form-group"> 
      <label for="file_tag">Tag</label> 
      <input type="text" name="file_tag" class="form-control" id="file_tag" placeholder="statement"> 
     </div> 

     <div class="form-group"> 
      <label for="file_description">Description</label> 
      <input type="text" name="file_description" class="form-control" id="file_description"> 
     </div> 

     <div class="form-group"> 
      <label for="file_date">Date</label> 
      <input type="date" name="file_date" class="form-control" id="file_date"> 
     </div> 

     <div class="form-group"> 
      <label for="file_location">File</label> 
      <input type="file" class="form-control" name="file_location" value="file"> 
      <p class="help-block">Select appropriate file for upload.</p> 
     </div> 

    <button type="button" class="btn btn-info" data-dismiss="modal">Cancel</button> 
    <button type="submit" class="btn btn-success">Upload</button> 


    </form> 
</div> 

나는 그것을 밖으로 작동하지 않을 수 있습니다, 시간이 온라인을 찾고 보냈다 ... 내 관심사는 Bootstraps Modal을 사용하고 있습니다. POST 데이터를 제대로 파악할 수 있는지 확실하지 않았습니다 ... 수동으로 ID를 입력하면 마치 ...

모든 도움을 주시면 대단히 감사하겠습니다.

+1

더 작은 유스 케이스를 jsfiddle 또는 비슷한 것으로 올려 놓는 것이 좋습니다. 코드를 따르기가 어렵고 질문에 더 명확하게 질문 할 수 있습니다. –

+0

'Index.php'에 이미 DB 연결을 설정했습니다. –

+0

https://nas.tgcowell.com/simple – tgcowell

답변

0

변경이

$id=isset($_POST['id_grab']); 

$id=isset($_POST['id_grab'])?$_POST['id_grab']:''; 
//if id_grab dont have a value then $id value will be '' 

isset() 반환 TRUE VAR이 존재하고, 그렇지 않으면 NULL, FALSE 이외의 값이있는 경우에.

+0

나는 위의 시도했는데, 지금 오류가 발생하는 것을 알게 : 쿼리를 실행하는 동안 오류가 발생했습니다 [SQL 구문에 오류가 있습니다; 올바른 구문이 MariaDB 서버 버전에 해당하는 매뉴얼을 확인하여 'at line 1'근처에서 사용하십시오. – tgcowell

+0

먼저'$ id' 값을 출력하려고합니다. 여러분이'_POST [ 'id_grab' ]' –

관련 문제