Are the division in…
Are the division in different tables..?
<?php if(!$conn){ } ?>
<!DOCTYPE html> <?php require'conn.php'?> <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="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Assign User To Different Division In MySQLi</h3> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-4"> <form method="POST" action="save.php"> <div class="form-group"> <label>Name</label> <input type="text" class="form-control" name="name" required="required"/> </div> <div class="form-group"> <label>Username</label> <input type="text" min="0" class="form-control" name="username" required="required"/> </div> <div class="form-group"> <label>Password</label> <input type="password" class="form-control" max="12" name="password" required="required"/> </div> <div class="form-group"> <label>Division</label> <select name="division" class="form-control" required="required"> <option value="">Select an option</option> <option value="Marketing">Marketing</option> <option value="Finance">Finance</option> <option value="Operations management">Operations management</option> <option value="Human Resource">Human Resource</option> <option value="IT">IT</option> </select> </div> <center><button class="btn btn-primary" name="save">Save</button></center> </form> </div> <div class="col-md-8"> <form method="POST" action=""> <div class="form-inline"> <label>Sort By Division: </label> <select name="division" class="form-control" required="required"> <option value="">Select an option</option> <option value="Marketing">Marketing</option> <option value="Finance">Finance</option> <option value="Operations management">Operations management</option> <option value="Human Resource">Human Resource</option> <option value="IT">IT</option> </select> <button class="btn btn-success" name="sort">Sort</button> </div> </form> <br /> <?php include'sort.php'?> </div> </div> </body> </html>
<?php require_once'conn.php'; $name=$_POST['name']; $username=$_POST['username']; $password=$_POST['password']; $division=$_POST['division']; mysqli_query($conn, "INSERT INTO `user` VALUES('', '$name', '$username', '$password', '$division')") or die(mysqli_error()); } ?>
<?php require_once'conn.php'; $division=$_POST['division']; ?> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Name</th> <th>Username</th> <th>Password</th> <th>Division</th> </tr> </thead> <tbody> <?php $query=mysqli_query($conn, "SELECT * FROM `user` WHERE `division`='$division'") or die(mysqli_error()); ?> <tr> <td><?php echo $fetch['name']?></td> <td><?php echo $fetch['username']?></td> <td>*********</td> <td><?php echo $fetch['division']?></td> </tr> <?php } ?> </tbody> </table> <?php }else{ ?> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Name</th> <th>Username</th> <th>Password</th> <th>Division</th> </tr> </thead> <tbody> <?php ?> <tr> <td><?php echo $fetch['name']?></td> <td><?php echo $fetch['username']?></td> <td>*********</td> <td><?php echo $fetch['division']?></td> </tr> <?php } ?> </tbody> </table> <?php } ?>