Display Mysql Data from database in form using PHP


<!DOCTYPE html>
<html>

<head>
<title>Bootstrap Fetch data from mysql</title>
<meta charset="utf-8">
<meta name="viewport" content="width-=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
table, th, td {
     border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "formdatainsert";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}

if(isset($_POST['submit'])){
$name=isset($_POST['name'])?$_POST['name']:'';
$email=isset($_POST['email'])?$_POST['email']:'';


$sql = "SELECT * from bootstrapinputs where name='$name' AND email='$email'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     //echo "<table><tr><th>ID</th><th>Email</th><th>Name</th></tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         //echo "<tr><td>" . $row["Id"]. "</td><td>" . $row["Email"]. " </td><td> " . $row["Name"]. "</td></tr>";
        
        echo '<div style="height: 117px;">';
            echo '<div style="float: left; width: 100px; margin-left: 19px;">';
                echo "<img width=92 height=72 alt='Unable to View' src='" . $row["Id"] . "'>";
            echo '</div>';
            echo '<div style="float: right; width: 575px; margin-top: 10px;">';
                echo '<span class="style5">'.'ID: '.$row["Id"] .'</span>';
                echo '<br>';      
                echo '<span class="style5">'.'Name: '.$row['Name'].'</span><br>';
                echo '<span class="style5">'.'Email: '.$row['Email'].'</span><br>';
                echo '<span class="style5">'.'Comments: '.$row['Comments'].'</span><br>';
                echo '<span class="style5">'.'Availabiliity: '.$row['Selectone'].'</span><br>';                
            echo '</div>';
        echo '</div>';
        
        
     }
    // echo "</table>";
} else {
     echo "0 results";
}
}
$conn->close();
?>
<div class="container">
<h2> Form elements</h2>
<p>The Form Below Contains input elements</p>
    <form role="form" class="form-horizontal" action="fetchbootstrap2.php" method="post">
        <div class="form-group">
          <label class="control-label col-sm-2" for="email">Email:</label>
          <div class="col-sm-10">
            <input type="email" class="form-control" value="one@example.com" name="email">
          </div>
        </div>
      
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">Name:</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="name">
          </div>
        </div>
  
        <div class="form-group">      
          <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default" name="submit">Submit</button>
          </div>
        </div>
      

    </form>
</body>
</html>

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Hyperledger Development with in 10 days — Day 6

Insert CheckBox and Radio button Data in MySQL Database Using PHP