Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $server = 'localhost';
- $user = 'root';
- $password = 'Thao1993@';
- $db = 'php_course';
- $conn = mysqli_connect($server,$user,$password,$db);
- if(!$conn){
- die("Connection failed : ".mysqli_connect_error());
- }
- ?>
- <?php include 'includes/db.php'; ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Retreiving data from database</title>
- <script src="js/jquery.js"></script>
- <script src="bootstrap/js/bootstrap.js"></script>
- <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
- </head>
- <body>
- <div class="container">
- <table class="table table-striped">
- <thead>
- <th>Id</th>
- <th>Name</th>
- <th>Email</th>
- <th>Gender</th>
- <th>Skills</th>
- <th>Country</th>
- </thead>
- <tbody>
- <?php
- $sql = "SELECT * from comments";
- $run_sql = mysqli_query($conn,$sql);
- while ($rows = mysqli_fetch_array($run_sql)) {
- echo '
- <tr>
- <td>'.$rows['id'].'</td>
- <td>'.$rows['name'].'</td>
- <td>'.$rows['email'].'</td>
- <td>'.$rows['gender'].'</td>
- <td>'.$rows['skill1'].','.$rows['skill2'].','.$rows['skill3'].','.$rows['skil4'].'</td>
- <td>'.$rows['country'].'</td>
- </tr>
- ';
- }
- ?>
- </tbody>
- </table>
- </div>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>New Form Using Bootstrap</title>
- <script src="js/jquery.js"></script>
- <script src="bootstrap/js/<h1>Submit Form</h1>
- bootstrap.js"></script>
- <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
- <style>
- .my-fixed{
- resize: none;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>Submit Form</h1>
- <form class="form-horizontal" action="form_process.php" method="post" role="form">
- <div class="form-group">
- <label for="name" class="control-label col-sm-2">Name*</label>
- <div class="col-sm-5">
- <input type="text" id="name" class="form-control" name="name" placeholder="Your Name" required>
- </div>
- </div>
- <div class="form-group">
- <label for="email" class="control-label col-sm-2">E-mail*</label>
- <div class="col-sm-5">
- <input type="email" id="email" class="form-control" name="email" placeholder="Your Email"required>
- </div>
- </div>
- <div class="form-group">
- <label for="subject" class="control-label col-sm-2">Subject</label>
- <div class="col-sm-5">
- <input type="text" id="subject" class="form-control" name="subject" placeholder="Add Your Subject">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2">Gender*</label>
- <div class="col-sm-2">
- <select class="form-control" name="gender"required>
- <option value="">Your Gender</option>
- <option value="male">Male</option>
- <option value="female">Female</option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2">Skills</label>
- <div class="col-sm-5">
- <label class="checkbox-inline"><input type="checkbox" name="skill1">HTML5</label>
- <label class="checkbox-inline"><input type="checkbox" name="skill2">Java</label>
- <label class="checkbox-inline"><input type="checkbox" name="skill3">JSP</label>
- <label class="checkbox-inline"><input type="checkbox" name="skill4">CSS</label>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2">Select your country*</label>
- <div class="col-sm-3">
- <select class="form-control" name="country" required>
- <option value="">Your Country</option>
- <option value="america">America</option>
- <option value="canada">Canada</option>
- <option value="spain">Spain</option>
- <option value="azerbaijan">Azerbaijan</option>
- </select>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2">Comments</label>
- <div class="col-sm-5">
- <textarea class="form-control my-fixed" name="comments"rows="8"></textarea>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2"></label>
- <div class="checkbox col-sm-5">
- <label><input type="checkbox"> Remember me</label>
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2"></label>
- <div class="col-sm-5">
- <input type="submit" class="btn btn-default" value="Submit Form" name="submit_form">
- </div>
- </div>
- </form>
- </div>
- </body>
- </html>
- <?php
- include 'includes/db.php';
- if (isset($_POST['submit_form'])) {
- $name = strip_tags($_POST['name']);
- $email = strip_tags($_POST['email']);
- $subject = htmlspecialchars($_POST['subject']);
- $gender = $_POST['gender'];
- $country = $_POST['country'];
- $comments = trim(htmlspecialchars($_POST['comments']));
- if(empty($_POST['skill1'])){
- $_POST['skill1'] = '';
- }
- if(empty($_POST['skill2'])){
- $_POST['skill2'] = '';
- }
- if(empty($_POST['skill3'])){
- $_POST['skill3'] = '';
- }
- if(empty($_POST['skil4'])){
- $_POST['skil4'] = '';
- }
- $ins_sql = "INSERT INTO comments(name,email,subject,gender,skill1,
- skill2,skill3,skil4,country,comments) VALUES('$name','$email','$subject',
- '$gender','$_POST[skill1]','$_POST[skill2]','$_POST[skill3]',
- '$_POST[skil4]','$country','$comments')";
- $run_sql = mysqli_query($conn,$ins_sql);
- }else {
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement