Skip to main content

MYSQLI SELECT table using Parameters Prepared Statements (PHP)

Select and fetch data from mysql table using PHP help of  Parameters Prepared Statements.

MYSQLI SELECT table using Parameters Prepared Statements (PHP)

Why use parameters in your php applications?
  1. This is secure
  2. This is error less
  3. Faster then any others
In this example, you can insert and fetch data from the table. so try this
MYSQLI SELECT table using Parameters Prepared Statements (PHP)

Source :

<?php
@$conn = mysqli_connect('localhost','root','','testdb') or die("Please check your database username and password")
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Insert into table</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#myform
{
margin:20px;
-webkit-box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
-moz-box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
}
</style>
</head>

<body>

<div id="myform" class="panel panel-primary">
<div class="panel-heading">My Secure form</div>
    <div class="panel-body">
    <div class="row">
    <div class="col-lg-12">
    <form method="post" enctype="multipart/form-data" action="?">
        <div class="row">
            <div class="col-lg-3">
                <div class="form-group">
                <label>Name</label>
                <input type="text" name="name" class="form-control">
                </div>
            </div>
            <div class="col-lg-3">
                <div class="form-group">
                <label>Email</label>
                <input type="text" name="email" class="form-control">
                </div>
            </div>
            <div class="col-lg-3">
                <div class="form-group">
                <label>Contact Number</label>
                <input type="text" name="cnum" class="form-control">
                </div>
            </div>
            <div class="col-lg-3">
                <div class="form-group">
                <label>Address</label>
                <input type="text" name="add" class="form-control">
                </div>
            </div>
            <div class="col-lg-12">
                <div class="form-group">
                <button class="btn btn-primary pull-right" type="submit" name="submit">
                Submit information
                </button>
                </div>
            </div>
          </div>
        </form>
        </div>
     </div>
        <div class="panel-footer">
<?php
if(isset($_POST['submit']))
{
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$contactn = mysqli_real_escape_string($conn, $_POST['cnum']);
$addrs = mysqli_real_escape_string($conn, $_POST['add']);

if($name != "" and  $email != "" and $contactn != "" and $addrs != "")
{
$insert = "INSERT INTO infotab(name,email,contact,address) VALUES(?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $insert))
{
echo "Opps Technical Problems....";
}
else
{
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $contactn, $addrs);
mysqli_stmt_execute($stmt);
}
echo "Data Inserted Successfully";
}
unset($stmt);
}
?>
        </div>
    </div>
</div>


<div class="panel panel-default" id="myform">
<div class="panel-heading">My Secure form</div>
    <div class="panel-body">
<div class="row">
    <div class="col-lg-12">
        <table class="table table-bordered">
        <thead>
            <tr>
                <th>Name</th>
                    <th>Email</th>
                    <th>Contact Number</th>
                    <th>Address</th>
                </tr>
            </thead>
            <tbody>
            <?php
if($stmt = $conn->
prepare("SELECT name,email,contact,address FROM infotab"))
{
$stmt->execute();
$stmt->bind_result($name,$email,$contact,$address);
while($stmt->fetch())
{
?>
<tr>
                <td><?php echo $name; ?></td>
                    <td><?php echo $email; ?></td>
                    <td><?php echo $contact; ?></td>
                    <td><?php echo $address; ?></td>
                </tr>
                <?php
}
}
?>
            </tbody>
        </table>
        </div>
    </div>
    </div>
</div>
</body>
</html>

Comments

Popular posts from this blog

How to Create a secure login panel with PHP & Mysql using parameters and session

Secure Login with PHP & Mysql Download project zip Requirement: you need an Apache and MySQL Server database on your device If your computer has xampp or wamp or mamp  or lamp that's great otherwise you need to install Apache and MySQL server Create a database login Run this query : CREATE TABLE admin ( id INT(6) AUTO_INCREMENT PRIMARY KEY, uname VARCHAR(30) NOT NULL, upass VARCHAR(30) NOT NULL ); INSERT INTO `admin` (`id`, `uname`, `upass`) VALUES (NULL, 'admin', 'admin1993'); That means you set your username =  admin and password = admin1993 Login Page: login.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Login Getway</title> <link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css" type="text/css"> <style> * { margin:0px; padding:0px; font-family:ar...

Create dynamic table using bootstrap (filter & find records)

Data Table With Bootstrap Download HTML file Into : In this table, you can short, filtering, find the record and many features you have been used but its very easy to use and configure. so don't get late lets introducing data table CSS:  Data table Stylesheet JS:   Data table js download this for your next project. or you can copy and paste bellow con on your project it's definitely working. Source : <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Data Table</title> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script> <script> $(document).ready(function(){       $('#myTable').DataTable(); }); </script> <link...

Which HTML Element helps to SEO Score up viewing result without boost by search engines

Here we discuss SEO and SEO friendly tags in HTML Add caption Meta tags: <meta charset="UTF-8"> <meta name="description" content="Here you can write your website descripsions"> <meta name="keywords" content="here you can write your description and all tahte sapareted by comma like (key1, key2, kay3)"> <meta name="author" content="Here you write website's authers name"> Headline tag: <h1>Headline tag 1</h1> <h2>Headline tag 1</h2> <h3>Headline tag 1</h3> This tag is most importent tag in website for SEO. Use H1 tag in wevery page of your website. its helps to identify content  Attribute : ALT This attribute used to find image form search engine. in this tag, you have to use for your website and type the title of the image. like  <img src="address.jpg" alt="title of your image">   TITLE This attribut...