bro can you give the ajax…
bro can you give the ajax part...i mean the one ajax you have not arrange hard for me to see the submit part for edit
<?php $conn=new PDO( 'mysql:host=localhost;dbname=db_pdo_store', 'root', ''); if(!$conn){ } ?>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="cotaniner-fluid"> <a class="navbar-brand">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Store Form Data With Modal Using PDO</h3> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-2"></div> <div class="col-md-8"> <button class="btn btn-success" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add user</button> <br /><br /> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> </thead> <tbody> <?php require_once 'conn.php'; $sql = "SELECT * FROM `user`"; $query = $conn->prepare($sql); $query->execute(); while($fetch = $query->fetch()){ ?> <tr> <td><?php echo $fetch['firstname']?></td> <td><?php echo $fetch['lastname']?></td> <td><?php echo $fetch['age']?></td> </tr> <?php } ?> </tbody> </table> </div> </div> <div class="modal fade" id="form_modal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <form method="POST" action="save_user.php"> <div class="modal-header"> <h3 class="modal-title">Add User</h3> </div> <div class="modal-body"> <div class="col-md-2"></div> <div class="col-md-8"> <div class="form-group"> <label>Firstname</label> <input type="text" name="firstname" class="form-control" required="required"/> </div> <div class="form-group"> <label>Lastname</label> <input type="text" name="lastname" class="form-control" required="required" /> </div> <div class="form-group"> <label>Age</label> <input type="number" name="age" class="form-control" min="0" max="200" required="required" /> </div> </div> </div> <div style="clear:both;"></div> <div class="modal-footer"> <button name="save" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button> <button class="btn btn-danger" type="button" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button> </div> </div> </form> </div> </div> </div> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/bootstrap.js"></script> </body> </html>
<?php require_once 'conn.php'; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $age = $_POST['age']; try{ $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO `user`(firstname, lastname, age) VALUES ('$firstname', '$lastname', '$age')"; }catch(PDOException $e){ echo $e->getMessage(); } $conn = null; } ?>