php - get value of checkbox submit to a variable -
i'm trying work out how value of checkbox submit variable id sql db.
below current code:
-- index.php
<?php $sql = "select * `file`"; if (!$result = $db->query($sql)){ die('there error running 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 * `file` file_id = $id"; if (!$result = $db->query($sql)){ die('there error running query [' . $db->error . ']'); } $row = $result->fetch_assoc(); ?> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </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 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> i can't work out, spent hours looking online... concern @ it's using bootstraps modal wasn't sure if able grat post data... if enter id manually works...
any assistance appreciated.
change
$id=isset($_post['id_grab']); to
$id=isset($_post['id_grab'])?$_post['id_grab']:''; //if id_grab dont have value $id value '' isset() returns true if var exists , has value other null, false otherwise.
Comments
Post a Comment