Showing posts with label PHP-Mysql. Show all posts
Showing posts with label PHP-Mysql. Show all posts

Create a DataGrid with PHP MySQLi and jQuery EasyUI

Create a DataGrid with PHP MySQLi and jQuery EasyUI
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Create a DataGrid with PHP MySQLi and jQuery EasyUI</title>
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <h2>Create a DataGrid with PHP MySQLi and jQuery EasyUI</h2>
    <p>Click the buttons on datagrid toolbar to do crud actions.</p>
    <table id="dg" title="Users Management" class="easyui-datagrid" url="getData.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" style="width:100%;height:400px;">
  <thead>
   <tr>
    <th field="first_name" width="50">First Name</th>
    <th field="last_name" width="50">Last Name</th>
    <th field="email" width="50">Email</th>
    <th field="phone" width="50">Phone</th>
   </tr>
  </thead>
 </table>
 <div id="toolbar">
  <div id="tb">
   <input id="term" placeholder="Type keywords...">
   <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>
  </div>
  <div id="tb2" style="">
   <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
   <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
   <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
  </div>
 </div>
 <div id="dlg" class="easyui-dialog" style="width:450px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
  <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
   <h3>User Information</h3>
   <div style="margin-bottom:10px">
    <input name="first_name" class="easyui-textbox" required="true" label="First Name:" style="width:100%">
   </div>
   <div style="margin-bottom:10px">
    <input name="last_name" class="easyui-textbox" required="true" label="Last Name:" style="width:100%">
   </div>
   <div style="margin-bottom:10px">
    <input name="email" class="easyui-textbox" required="true" validType="email" label="Email:" style="width:100%">
   </div>
   <div style="margin-bottom:10px">
    <input name="phone" class="easyui-textbox" required="true" label="Phone:" style="width:100%">
   </div>
  </form>
 </div>
 <div id="dlg-buttons">
  <a href="javascript:void(0);" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px;">Save</a>
  <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close');" style="width:90px;">Cancel</a>
 </div>
 <script type="text/javascript">
 function doSearch(){
  $('#dg').datagrid('load', {
   term: $('#term').val()
  });
 }
   
 var url;
 function newUser(){
  $('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
  $('#fm').form('clear');
  url = 'addData.php';
 }
 function editUser(){
  var row = $('#dg').datagrid('getSelected');
  if (row){
   $('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
   $('#fm').form('load',row);
   url = 'editData.php?id='+row.id;
  }
 }
 function saveUser(){
  $('#fm').form('submit',{
   url: url,
   onSubmit: function(){
    return $(this).form('validate');
   },
   success: function(response){
    var respData = $.parseJSON(response);
    if(respData.status == 0){
     $.messager.show({
      title: 'Error',
      msg: respData.msg
     });
    }else{
     $('#dlg').dialog('close');
     $('#dg').datagrid('reload');
    }
   }
  });
 }
 function destroyUser(){
  var row = $('#dg').datagrid('getSelected');
  if (row){
   $.messager.confirm('Confirm','Are you sure you want to delete this user?',function(r){
    if (r){
     $.post('deleteData.php', {id:row.id}, function(response){
      if(response.status == 1){
       $('#dg').datagrid('reload');
      }else{
       $.messager.show({
        title: 'Error',
        msg: respData.msg
       });
      }
     },'json');
    }
   });
  }
 }
 </script>
</body>
</html>
//getData.php
<?php
include"dbcon.php"; 
$page = isset($_POST['page']) ? intval($_POST['page']) : 1; 
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10; 
 
$searchTerm = isset($_POST['term']) ? $conn->real_escape_string($_POST['term']) : ''; 
 
$offset = ($page-1)*$rows; 
 
$result = array(); 

$whereSQL = "first_name LIKE '$searchTerm%' OR last_name LIKE '$searchTerm%' OR email LIKE '$searchTerm%' OR phone LIKE '$searchTerm%'"; 
$result = $conn->query("SELECT COUNT(*) FROM tbl_users WHERE $whereSQL"); 
$row = $result->fetch_row(); 
$response["total"] = $row[0]; 

$result = $conn->query( "SELECT * FROM tbl_users WHERE $whereSQL ORDER BY id DESC LIMIT $offset,$rows"); 
 
$users = array(); 
while($row = $result->fetch_assoc()){ 
    array_push($users, $row); 
} 
$response["rows"] = $users; 

echo json_encode($response);
?>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
//addData.php
<?php
include"dbcon.php"; 
$response = array( 
    'status' => 0, 
    'msg' => 'Some problems occurred, please try again.' 
); 
if(!empty($_REQUEST['first_name']) && !empty($_REQUEST['last_name']) && !empty( $_REQUEST['email']) && !empty($_REQUEST['phone'])){ 
    $first_name = $_REQUEST['first_name']; 
    $last_name = $_REQUEST['last_name']; 
    $email = $_REQUEST['email']; 
    $phone = $_REQUEST['phone'];
 
    $sql = "INSERT INTO tbl_users(first_name,last_name,email,phone) VALUES ('$first_name','$last_name','$email','$phone')"; 
    $insert = $conn->query($sql); 
 
 if($insert){ 
        $response['status'] = 1; 
        $response['msg'] = 'User data has been added successfully!'; 
    } 
}else{ 
    $response['msg'] = 'Please fill all the mandatory fields.'; 
}
echo json_encode($response); 
?>
//editData.php
<?php
include"dbcon.php"; 
$response = array( 
    'status' => 0, 
    'msg' => 'Some problems occurred, please try again.' 
);
if(!empty($_REQUEST['first_name']) && !empty($_REQUEST['last_name']) && !empty( $_REQUEST['email']) && !empty($_REQUEST['phone'])){ 
    $first_name = $_REQUEST['first_name']; 
    $last_name = $_REQUEST['last_name']; 
    $email = $_REQUEST['email']; 
    $phone = $_REQUEST['phone']; 
     
    if(!empty($_REQUEST['id'])){ 
        $id = intval($_REQUEST['id']); 
         
    
        $sql = "UPDATE tbl_users SET first_name='$first_name', last_name='$last_name', email='$email', phone='$phone' WHERE id = $id"; 
        $update = $conn->query($sql); 
         
        if($update){ 
            $response['status'] = 1; 
            $response['msg'] = 'User data has been updated successfully!'; 
        } 
    } 
}else{ 
    $response['msg'] = 'Please fill all the mandatory fields.'; 
} 
echo json_encode($response); 
?>
//deleteData.php
<?php
include"dbcon.php"; 
$response = array( 
    'status' => 0, 
    'msg' => 'Some problems occurred, please try again.' 
); 
if(!empty($_REQUEST['id'])){ 
    $id = intval($_REQUEST['id']); 
     

    $sql = "DELETE FROM tbl_users WHERE id = $id"; 
    $delete = $conn->query($sql); 
     
    if($delete){ 
        $response['status'] = 1; 
        $response['msg'] = 'User data has been deleted successfully!'; 
    } 
} 
echo json_encode($response);
?>

Create a Progress Bar Data Insert using PHP Mysqli bootstrap and Jquery Ajax

Create a Progress Bar Data Insert using PHP Mysqli bootstrap and Jquery Ajax
<!DOCTYPE html>
<html>
 <head>
  <title>Create a Progress Bar Data Insert using PHP Mysqli bootstrap and Jquery Ajax</title>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
 $(document).ready(function(){
 $('#sample_form').on('submit', function(event){
   event.preventDefault();
   var count_error = 0;

   if($('#username').val() == '')
   {
    $('#first_name_error').text('User Name is required');
    count_error++;
   }
   else
   {
    $('#first_name_error').text('');
   }

   if($('#useremail').val() == '')
   {
    $('#last_name_error').text('Email is required');
    count_error++;
   }
   else
   {
    $('#last_name_error').text('');
   }

   if(count_error == 0)
   {
    $.ajax({
   url:"ajax_progressbar.php",
   method:"POST",
   data:$(this).serialize(),
   beforeSend:function()
   {
    $('#save').attr('disabled', 'disabled');
    $('#process').css('display', 'block');
   },
   success:function(data)
   { 
    var percentage = 0;

    var timer = setInterval(function(){
     percentage = percentage + 20;
     progress_bar_process(percentage, timer,data);
    }, 1000);
   }
  })
   }
   else
   {
    return false;
   }
   
  });
  
  function progress_bar_process(percentage, timer,data)
  {
 $('.progress-bar').css('width', percentage + '%');
 if(percentage > 100)
 {
  clearInterval(timer);
  $('#sample_form')[0].reset();
  $('#process').css('display', 'none');
  $('.progress-bar').css('width', '0%');
  $('#save').attr('disabled', false);
  $('#success_message').html(data);
  setTimeout(function(){
   $('#success_message').html('');
  }, 5000);
 }
  }
  
 });
</script>
 </head>
 <body>
  <br />
  <br />
  <div class="container">
   <h1 align="center">Create a Progress Bar Data Insert using PHP Mysqli bootstrap and Jquery Ajax</h1>
   <br />
   <div class="panel panel-default">
    <div class="panel-heading">
     <h3 class="panel-title">Registration</h3>
    </div>
      <div class="panel-body">
       <span id="success_message"></span>
       <form method="post" id="sample_form">
     <div class="form-group">
        <label>User Name</label>
         <input type="text" name="username" id="username" class="form-control" />
         <span id="first_name_error" class="text-danger"></span>
        </div>
  <div class="form-group">
         <label>Email</label>
         <input type="text" name="useremail" id="useremail" class="form-control" />
         <span id="last_name_error" class="text-danger"></span>
        </div>
  <div class="form-group" align="center">
         <input type="submit" name="save" id="save" class="btn btn-info" value="Save" />
        </div>
       </form>
       <div class="form-group" id="process" style="display:none;">
        <div class="progress">
       <div class="progress-bar progress-bar-striped active bg-success" role="progressbar" aria-valuemin="0" aria-valuemax="100" style=""></div>
      </div>
       </div>
      </div>
     </div>
  </div>
 </body>
</html>
//ajax_progressbar.php
<?php
include"dbcon.php"; 
if(isset($_POST["username"]))
{
  $username  = $_POST["username"];
  $useremail  = $_POST["useremail"];
  $sql = "INSERT INTO tbl_user (username, useremail) VALUES ('".$username."','".$useremail."')";
    if ($conn->query($sql) === TRUE) {
     echo "<div class='alert alert-success'>New record created successfully</div>";
     $conn->close();
    } else {
    echo "Error: " . $sql . "<br>" . $conn->error."";
    }
}
?>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>

Add/Remove Input Fields Dynamically with PHP Mysqli and JQuery

Add/Remove Input Fields Dynamically with PHP Mysqli and JQuery
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add/Remove Input Fields Dynamically with bootstrap PHP Mysqli and JQuery</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>    
</head>
<body>
 <script>
$(document).ready(function() {

var MaxInputs       = 8; //maximum input boxes allowed
var InputsWrapper   = $("#InputsWrapper"); //Input boxes wrapper ID
var AddButton       = $("#AddMoreFileBox"); //Add button ID

var x = InputsWrapper.length; //initlal text box count
var FieldCount=1; //to keep track of text box added

$(AddButton).click(function (e)  //on add input button click
{
        if(x <= MaxInputs) //max input box allowed
        {
            FieldCount++; //text box added increment
            //add input box
            $(InputsWrapper).append('<div class="row"><p class="col-xs-6"><input type="text" placeholder="Enter your skill" class="form-control skill_list" name="skill[]" id="field_'+ FieldCount +'" value="Enter your skill '+ FieldCount +'"/></p><a href="#" class="btn btn-danger removeclass">×</a></div>');
            x++; //text box increment
        }
return false;
});

$("body").on("click",".removeclass", function(e){ //user click on remove text
        if( x > 1 ) {
                $(this).parent('div').remove(); //remove text box
                x--; //decrement textbox
        }
return false;
})
 $('#submit').click(function(){            
           $.ajax({  
                url:"skill.php",  
                method:"POST",  
                data:$('#add_skills').serialize(),  
                success:function(data)  
                {  
                     $('#resultbox').html(data);  
                     $('#add_skills')[0].reset();  
                }  
           });  
      }); 
});
</script>
<style>
.row {padding:10px;}
</style>
<div class="container">  
                <br />  
                <br />  
                <h2 align="center">Add/Remove Input Fields Dynamically with PHP Mysqli and JQuery</h2><div id="resultbox"></div>  
                <div class="form-group">  
                     <form name="add_skills" id="add_skills">  
                                    <div id="InputsWrapper">
          <div class="row">
                                         <div class="col-xs-6"><input type="text" name="skill[]" placeholder="Enter your skill" class="form-control name_list" /></div>
                                         <div class="col-xs-6"><button type="button" name="add" id="AddMoreFileBox" class="btn btn-success">Add More</button></div>
           </div>
         </div>
         <br/>
                               <input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />  
                     </form>  
                </div>  
           </div>  
</body>
</html>
//skill.php
<?php
include"dbcon.php"; 
 $number = count($_POST["skill"]);  
 if($number > 0)  
 {  
      for($i=0; $i<$number; $i++)  
      {  
           if(trim($_POST["skill"][$i] != ''))  
           {  
    $skillname = $_POST["skill"][$i];
    $sql = "INSERT INTO skills (skillname) VALUES ('".$skillname."')";
    if ($conn->query($sql) === TRUE) {
    } else {
    echo "Error: " . $sql . "<br>" . $conn->error."";
    }
    
           }  
      } 
   echo "<p class='btn btn-info' align='center'>New record created successfully</p>";
   $conn->close(); 
 }  
 else  
 {  
      echo "Please Enter Name";  
 } 
?>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>

HTML5 Inline Edit with jQuery Ajax, PHP & MYSQLi

HTML5 Inline Edit with jQuery Ajax, PHP & MYSQLi
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 Inline Content Editing with jQuery, PHP & MYSQL</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function(){
    var message_status = $("#status");
    $("td[contenteditable=true]").blur(function(){
        var field_userid = $(this).attr("id");
        var value = $(this).text();
  var string = value;
  $.post("ajax_inlineupdate.php", { string: string,field_userid: field_userid}, function(data) {
           if(data != '')
     {
   message_status.show();
   message_status.text(data);
   //hide the message
   setTimeout(function(){message_status.hide()},1000);
     }
        });
    });
});
</script>
<style>
table.zebra-style {
 font-family:"Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
 text-align:left;
 border:1px solid #ccc;
 margin-bottom:25px;
 width:50%
}
table.zebra-style th {
 color: #444;
 font-size: 13px;
 font-weight: normal;
 padding: 10px 8px;
}
table.zebra-style td {
 color: #777;
 padding: 8px;
 font-size:13px;
}
table.zebra-style tr.odd {
 background:#f2f2f2;
}
body {
 background:#fafafa;
}
.container {
 width: 800px;
 border: 1px solid #C4CDE0;
 border-radius: 2px;
 margin: 0 auto;
 height: 1300px;
 background:#fff;
 padding-left:10px;
}
#status { padding:10px; background:#88C4FF; color:#000; font-weight:bold; font-size:12px; margin-bottom:10px; display:none; width:90%; }
</style>
</head>
<body>
  <h1>HTML5 Inline Edit with jQuery Ajax, PHP & MYSQLi</h1>
  <div id="status"></div>
<table class="table zebra-style">
    <thead>
      <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>City</th>
      </tr>
    </thead>
    <tbody>
      <tr class="odd">
        <td>1</td>
        <td id="f:1" contenteditable="true">Michael</td>
        <td id="l:1" contenteditable="true">Holz</td>
        <td id="c:1" contenteditable="true">Olongapo City</td>
      </tr>
      <tr>
        <td>2</td>
        <td id="f:2" contenteditable="true">Paula</td>
        <td id="l:2" contenteditable="true">Wilson</td>
        <td id="c:2" contenteditable="true">California</td>
      </tr>
      <tr class="odd">
        <td>3</td>
        <td id="f:3" contenteditable="true">Antonio</td>
        <td id="l:3" contenteditable="true">Moreno</td>
        <td id="c:3" contenteditable="true">Olongapo City</td>
      </tr>
    </tbody>
 </table>
</body>
</html>
//ajax_inlineupdate.php
<?php
include"dbcon.php"; 
$string  = $_POST['string']; 
$field_userid  = $_POST['field_userid']; 
if ($string==''){
 echo "<p class='btn btn-info' align='center'>Please Insert field</p>";
}else{
 $strings = $field_userid;
 $fields = $strings[0]; 
 if ($fields=='f') {
  $setrs = "fname='$string'"; 
 }elseif ($fields=='l') {
  $setrs = "lname='$string'"; 
 }elseif ($fields=='c') {
  $setrs = "city='$string'"; 
 }else{$setrs = "";} 
 $getid = substr($field_userid, 2); 
 $sql = "UPDATE user SET $setrs WHERE id = '$getid' ";
 if ($conn->query($sql) === TRUE) {
  echo "Record updated successfully";
 } else {
  echo "Error updating record: " . $conn->error;
 }  
} 
?>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>

Data Table with Add, Edit and Delete Row Using PHP,Mysqli jquery Ajax

Data Table with Add, Edit and Delete Row Using PHP,Mysqli jquery Ajax
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Data Table with Add, Edit and Delete Row Using PHP,Mysqli jquery Ajax</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<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/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
    body {
        color: #404E67;
        background: #F5F7FA;
  font-family: 'Open Sans', sans-serif;
 }
 .table-wrapper {
  width: 700px;
  margin: 30px auto;
        background: #fff;
        padding: 20px; 
        box-shadow: 0 1px 1px rgba(0,0,0,.05);
    }
    .table-title {
        padding-bottom: 10px;
        margin: 0 0 10px;
    }
    .table-title h2 {
        margin: 6px 0 0;
        font-size: 22px;
    }
    .table-title .add-new {
        float: right;
  height: 30px;
  font-weight: bold;
  font-size: 12px;
  text-shadow: none;
  min-width: 100px;
  border-radius: 50px;
  line-height: 13px;
    }
 .table-title .add-new i {
  margin-right: 4px;
 }
    table.table {
        table-layout: fixed;
    }
    table.table tr th, table.table tr td {
        border-color: #e9e9e9;
    }
    table.table th i {
        font-size: 13px;
        margin: 0 5px;
        cursor: pointer;
    }
    table.table th:last-child {
        width: 100px;
    }
    table.table td a {
  cursor: pointer;
        display: inline-block;
        margin: 0 5px;
  min-width: 24px;
    }   
 table.table td a.add {
        color: #27C46B;
    }
    table.table td a.edit {
        color: #FFC107;
    }
    table.table td a.delete {
        color: #E34724;
    }
    table.table td i {
        font-size: 19px;
    }
 table.table td a.add i {
        font-size: 24px;
     margin-right: -1px;
        position: relative;
        top: 3px;
    }    
    table.table .form-control {
        height: 32px;
        line-height: 32px;
        box-shadow: none;
        border-radius: 2px;
    }
 table.table .form-control.error {
  border-color: #f50000;
 }
 table.table td .add {
  display: none;
 }
</style>
<script type="text/javascript">
$(document).ready(function(){
 $('[data-toggle="tooltip"]').tooltip();
 var actions = $("table td:last-child").html();
 // Append table with add row form on add new button click
    $(".add-new").click(function(){
  $(this).attr("disabled", "disabled");
  var index = $("table tbody tr:last-child").index();
        var row = '<tr>' +
            '<td><input type="text" class="form-control" name="name" id="txtname"></td>' +
            '<td><input type="text" class="form-control" name="department" id="txtdepartment"></td>' +
            '<td><input type="text" class="form-control" name="phone" id="txtphone"></td>' +
   '<td>' + actions + '</td>' +
        '</tr>';
     $("table").append(row);  
  $("table tbody tr").eq(index + 1).find(".add, .edit").toggle();
        $('[data-toggle="tooltip"]').tooltip();
    });
 
 // Add row on add button click
 $(document).on("click", ".add", function(){
  var empty = false;
  var input = $(this).parents("tr").find('input[type="text"]');
        input.each(function(){
   if(!$(this).val()){
    $(this).addClass("error");
    empty = true;
   } else{
                $(this).removeClass("error");
            }
  });
  var txtname = $("#txtname").val();
  var txtdepartment = $("#txtdepartment").val();
  var txtphone = $("#txtphone").val();
  $.post("ajax_add.php", { txtname: txtname, txtdepartment: txtdepartment, txtphone: txtphone}, function(data) {
   $("#displaymessage").html(data);
  });
  $(this).parents("tr").find(".error").first().focus();
  if(!empty){
   input.each(function(){
    $(this).parent("td").html($(this).val());
   });   
   $(this).parents("tr").find(".add, .edit").toggle();
   $(".add-new").removeAttr("disabled");
  } 
    });
 // Delete row on delete button click
 $(document).on("click", ".delete", function(){
        $(this).parents("tr").remove();
  $(".add-new").removeAttr("disabled");
  var id = $(this).attr("id");
  var string = id;
  $.post("ajax_delete.php", { string: string}, function(data) {
   $("#displaymessage").html(data);
  });
    });
 // update rec row on edit button click
 $(document).on("click", ".update", function(){
  var id = $(this).attr("id");
  var string = id;
        var txtname = $("#txtname").val();
  var txtdepartment = $("#txtdepartment").val();
  var txtphone = $("#txtphone").val();
  $.post("ajax_update.php", { string: string,txtname: txtname, txtdepartment: txtdepartment, txtphone: txtphone}, function(data) {
   $("#displaymessage").html(data);
  });
    });
 // Edit row on edit button click
 $(document).on("click", ".edit", function(){  
        $(this).parents("tr").find("td:not(:last-child)").each(function(i){
   if (i=='0'){
    var idname = 'txtname';
   }else if (i=='1'){
    var idname = 'txtdepartment';
   }else if (i=='2'){
    var idname = 'txtphone';
   }else{} 
   $(this).html('<input type="text" name="updaterec" id="' + idname + '" class="form-control" value="' + $(this).text() + '">');
  });  
  $(this).parents("tr").find(".add, .edit").toggle();
  $(".add-new").attr("disabled", "disabled");
  $(this).parents("tr").find(".add").removeClass("add").addClass("update");
    });
});
</script> 
</head>
<body>
    <div class="container"><p><h1 align="center">Data Table with Add and Delete Row Using PHP,Mysqli jquery</h1><div id="displaymessage"></div></p>
        <div class="table-wrapper">
            <div class="table-title">
                <div class="row">
                    <div class="col-sm-8"><h2>Employee <b>Details</b></h2></div>
                    <div class="col-sm-4">
                        <button type="button" class="btn btn-info add-new"><i class="fa fa-plus"></i> Add New</button>
                    </div>
                </div>
            </div>
   <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Department</th>
                        <th>Phone</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
<?php 
include"dbcon.php"; 
$query_pag_data = "SELECT * from students";
$result_pag_data = mysqli_query($conn, $query_pag_data);
while($row = mysqli_fetch_assoc($result_pag_data)) {
 $student_id=$row['student_id']; 
 $student_name=$row['student_name']; 
 $department=$row['department']; 
 $phone=$row['phone']; 
?>
                    <tr>
                        <td><?php echo $student_name; ?></td>
                        <td><?php echo $department; ?></td>
                        <td><?php echo $phone; ?></td>
                        <td>
       <a class="add" title="Add" data-toggle="tooltip" id="<?php echo $student_id; ?>"><i class="fa fa-user-plus"></i></a>
                            <a class="edit" title="Edit" data-toggle="tooltip" id="<?php echo $student_id; ?>"><i class="fa fa-pencil"></i></a>
                            <a class="delete" title="Delete" data-toggle="tooltip" id="<?php echo $student_id; ?>"><i class="fa fa-trash-o"></i></a>
                        </td>
                    </tr>   
<?php } ?>     
                </tbody>
            </table>
        </div>
    </div>     
</body>
</html>                            
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
<?php
include"dbcon.php"; 
$txtname  = $_POST['txtname'];
$txtdepartment  = $_POST['txtdepartment'];
$txtphone  = $_POST['txtphone'];
if ($txtname==''){
 echo "<p class='btn btn-info' align='center'>Please Insert YOUr name</p>";
}else{ 
 $sql = "INSERT INTO students (student_name, department, phone)
 VALUES ('".$txtname."','".$txtdepartment."','".$txtphone."')";
 if ($conn->query($sql) === TRUE) {
 echo "<p class='btn btn-info' align='center'>New record created successfully</p>";
 } else {
 echo "Error: " . $sql . "<br>" . $conn->error."";
 }
 $conn->close();
} 
?>
<?php
include"dbcon.php"; 
 $id=$_POST['string'];
 $sql = "delete from students where student_id='$id'";
 if ($conn->query($sql) === TRUE) {
  echo "<p class='btn btn-info' align='center'>Record deleted successfully</p>";
 } else {
  echo "Error deleting record: " . $conn->error;
 } 

?>
<?php
include"dbcon.php"; 
$string  = $_POST['string'];
$txtname  = $_POST['txtname'];
$txtdepartment  = $_POST['txtdepartment'];
$txtphone  = $_POST['txtphone'];
if ($txtname==''){
 echo "<p class='btn btn-info' align='center'>Please Insert YOUr name</p>";
}else{
 $sql = "UPDATE students SET student_name='$txtname', department='$txtdepartment', phone='$txtphone' WHERE student_id = '$string' ";
 if ($conn->query($sql) === TRUE) {
  echo "Record updated successfully";
 } else {
  echo "Error updating record: " . $conn->error;
 } 
}
?>

PHP MySQLi Insert Data Into Database

PHP MySQLi Insert Data Into Database
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP MySQLi Insert Data Into Database</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testingdb";
// 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"])){
 $sql = "INSERT INTO students (student_name, student_email, student_city)
 VALUES ('".$_POST["stu_name"]."','".$_POST["stu_email"]."','".$_POST["stu_city"]."')";

 if ($conn->query($sql) === TRUE) {
 echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
 } else {
 echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
 }
 $conn->close();
}
?>
<div id="main">
<center>
<h1>Insert data into database using mysqli</h1>
<div id="registration">
<h2>Student's Form</h2>
<hr/>
<form action="" method="post">
<label>Student Name :</label>
<input type="text" name="stu_name" id="name" required="required" placeholder="Please Enter Name"/><br /><br />
<label>Student Email :</label>
<input type="email" name="stu_email" id="email" required="required" placeholder="john123@gmail.com"/><br/><br />
<label>Student City :</label>
<input type="text" name="stu_city" id="city" required="required" placeholder="Please Enter Your City"/><br/><br />
<input type="submit" value=" Submit " name="submit"/><br />
</form>
</div>
</center>
</div>
<style>
@import url(http://fonts.googleapis.com/css?family=Raleway);
#main{
 width:100%;
 font-family: 'Raleway', sans-serif;
}
h2{
 background-color: #C4F980;
 text-align:center;
 border-radius: 10px 10px 0 0;
 margin: -10px -40px;
 padding: 15px;
}
hr{
 border:0;
 border-bottom:1px solid #ccc;
 margin: 10px -40px;
 margin-bottom: 30px;
}
#registration{
 width:300px;text-align:left;
 border-radius: 10px;
 font-family:raleway;
 border: 2px solid #ccc;
 padding: 10px 40px 25px;
 margin-top: 70px;
}
input[type=text],input[type=email]{
 width:99.5%;
 padding: 10px;
 margin-top: 8px;
 border: 1px solid #ccc;
 padding-left: 5px;
 font-size: 16px;
 font-family:raleway;
}
input[type=submit]{
 width: 100%;
 background-color:#7ECF16;
 color: white;
 border: 2px solid #6BB30F;
 padding: 10px;
 font-size:20px;
 cursor:pointer;
 border-radius: 5px;
 margin-bottom: -12px;
}
</style>
</body>
</html>       

Data Table using Mysqli Database and Bootstrap with Modal Form and pagenation

Data Table using Mysqli Database and Bootstrap with Modal Form
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Data Table using Mysqli Database and Bootstrap with Modal Form</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<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/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
    body {
        color: #566787;
  background: #f5f5f5;
  font-family: 'Varela Round', sans-serif;
  font-size: 13px;
 }
 .table-wrapper {
        background: #fff;
        padding: 20px 25px;
        margin: 30px 0;
  border-radius: 3px;
        box-shadow: 0 1px 1px rgba(0,0,0,.05);
    }
 .table-title {        
  padding-bottom: 15px;
  background: #0d2438;
  color: #fff;
  padding: 16px 30px;
  margin: -20px -25px 10px;
  border-radius: 3px 3px 0 0;
    }
    .table-title h2 {
  margin: 5px 0 0;
  font-size: 24px;
 }
 .table-title .btn-group {
  float: right;
 }
 .table-title .btn {
  color: #fff;
  float: right;
  font-size: 13px;
  border: none;
  min-width: 50px;
  border-radius: 2px;
  border: none;
  outline: none !important;
  margin-left: 10px;
 }
 .table-title .btn i {
  float: left;
  font-size: 21px;
  margin-right: 5px;
 }
 .table-title .btn span {
  float: left;
  margin-top: 2px;
 }
    table.table tr th, table.table tr td {
        border-color: #e9e9e9;
  padding: 12px 15px;
  vertical-align: middle;
    }
 table.table tr th:first-child {
  width: 60px;
 }
 table.table tr th:last-child {
  width: 100px;
 }
    table.table-striped tbody tr:nth-of-type(odd) {
     background-color: #fcfcfc;
 }
 table.table-striped.table-hover tbody tr:hover {
  background: #f5f5f5;
 }
    table.table th i {
        font-size: 13px;
        margin: 0 5px;
        cursor: pointer;
    } 
    table.table td:last-child i {
  opacity: 0.9;
  font-size: 22px;
        margin: 0 5px;
    }
 table.table td a {
  font-weight: bold;
  color: #566787;
  display: inline-block;
  text-decoration: none;
  outline: none !important;
 }
 table.table td a:hover {
  color: #2196F3;
 }
 table.table td a.edit {
        color: #FFC107;
    }
    table.table td a.delete {
        color: #F44336;
    }
    table.table td i {
        font-size: 19px;
    }
 table.table .avatar {
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 10px;
 }

    .pagination {
        float: right;
        margin: 0 0 5px;
    }
    .pagination li a {
        border: none;
        font-size: 13px;
        min-width: 30px;
        min-height: 30px;
        color: #999;
        margin: 0 2px;
        line-height: 30px;
        border-radius: 2px !important;
        text-align: center;
        padding: 0 6px;
    }
    .pagination li a:hover {
        color: #666;
    } 
    .pagination li.active a, .pagination li.active a.page-link {
        background: #03A9F4;
    }
    .pagination li.active a:hover {        
        background: #0397d6;
    }
 .pagination li.disabled i {
        color: #ccc;
    }
    .pagination li i {
        font-size: 16px;
        padding-top: 6px
    }
    .hint-text {
        float: left;
        margin-top: 10px;
        font-size: 13px;
    } 
   
 /* Custom checkbox */
 .custom-checkbox {
  position: relative;
 }
 .custom-checkbox input[type="checkbox"] {    
  opacity: 0;
  position: absolute;
  margin: 5px 0 0 3px;
  z-index: 9;
 }
 .custom-checkbox label:before{
  width: 18px;
  height: 18px;
 }
 .custom-checkbox label:before {
  content: '';
  margin-right: 10px;
  display: inline-block;
  vertical-align: text-top;
  background: white;
  border: 1px solid #bbb;
  border-radius: 2px;
  box-sizing: border-box;
  z-index: 2;
 }
 .custom-checkbox input[type="checkbox"]:checked + label:after {
  content: '';
  position: absolute;
  left: 6px;
  top: 3px;
  width: 6px;
  height: 11px;
  border: solid #000;
  border-width: 0 3px 3px 0;
  transform: inherit;
  z-index: 3;
  transform: rotateZ(45deg);
 }
 .custom-checkbox input[type="checkbox"]:checked + label:before {
  border-color: #03A9F4;
  background: #03A9F4;
 }
 .custom-checkbox input[type="checkbox"]:checked + label:after {
  border-color: #fff;
 }
 .custom-checkbox input[type="checkbox"]:disabled + label:before {
  color: #b8b8b8;
  cursor: auto;
  box-shadow: none;
  background: #ddd;
 }
 /* Modal styles */
 .modal .modal-dialog {
  max-width: 400px;
 }
 .modal .modal-header, .modal .modal-body, .modal .modal-footer {
  padding: 20px 30px;
 }
 .modal .modal-content {
  border-radius: 3px;
 }
 .modal .modal-footer {
  background: #ecf0f1;
  border-radius: 0 0 3px 3px;
 }
    .modal .modal-title {
        display: inline-block;
    }
 .modal .form-control {
  border-radius: 2px;
  box-shadow: none;
  border-color: #dddddd;
 }
 .modal textarea.form-control {
  resize: vertical;
 }
 .modal .btn {
  border-radius: 2px;
  min-width: 100px;
 } 
 .modal form label {
  font-weight: normal;
 }
</style> 
<script type="text/javascript">
$(document).ready(function(){
 // Activate tooltip
 $('[data-toggle="tooltip"]').tooltip();
 
 // Select/Deselect checkboxes
 var checkbox = $('table tbody input[type="checkbox"]');
 $("#selectAll").click(function(){
  if(this.checked){
   checkbox.each(function(){
    this.checked = true;                        
   });
  } else{
   checkbox.each(function(){
    this.checked = false;                        
   });
  } 
 });
 checkbox.click(function(){
  if(!this.checked){
   $("#selectAll").prop("checked", false);
  }
 });
    $('#cmdeleteselected').click (function(event) {
  event.preventDefault();
        var selected = new Array();
   $("input:checkbox[name=options]:checked").each(function() {
    selected.push($(this).val());
   });
  var selectedString = selected.join(",");
        $.post("ajaxdeleteselected.php", {selected: selected },
        function(data){
   $('#deleteEmployeeModalselected').modal('hide');
            $('.result').html(data);
        });  
    });
});
</script>
</head>
<body>
<?php 
include"dbcon.php"; 
if(isset($_POST["cmdaddnew"])){
 $sql = "INSERT INTO tblemployees (fullname, emailadd, address, phone)
 VALUES ('".$_POST["fullname"]."','".$_POST["emailadd"]."','".$_POST["address"]."','".$_POST["phone"]."')";
 if ($conn->query($sql) === TRUE) {
 echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
 } else {
 echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
 }
}
$page = (isset($_GET['page']))?$_GET['page']:'';
$editemployee = (isset($_GET['editemployee']))?$_GET['editemployee']:'';
$deleteemployee = (isset($_GET['deleteemployee']))?$_GET['deleteemployee']:'';

if ($deleteemployee==''){
}else{
echo "<script type= 'text/javascript'>$(document).ready(function(){ $('#deleteEmployeeModal').modal() });</script>";
}
if(isset($_POST["cmdelete"])){
   $sql = "DELETE FROM tblemployees WHERE id='$deleteemployee'";
 if ($conn->query($sql) === TRUE) {
  echo "<script type= 'text/javascript'>alert('Record deleted successfully');
  window.location.replace('bootstrap_data_table_with_modal_form.php');</script>";  
 } else {
  echo "<script type= 'text/javascript'>alert('Error deleting record: " . $sql . "<br>" . $conn->error."');</script>"; 
 }
}
if ($editemployee==''){
}else{
 echo "<script type= 'text/javascript'>$(document).ready(function(){ $('#editEmployeeModal').modal() });</script>";
 $results = mysqli_query($conn,"SELECT * FROM tblemployees Where id=$editemployee");
 while($row = mysqli_fetch_array($results))
 {
  $editid = $row["id"];
  $edit_fullname = $row["fullname"];
  $edit_emailadd = $row["emailadd"];
  $edit_address = $row["address"];
  $edit_phone = $row["phone"];
 }
}

if(isset($_POST["cmdedit"])){
   $editname = $_POST["editname"];
   $editemail = $_POST["editemail"];
   $editaddress = $_POST["editaddress"];
   $editphone = $_POST["editphone"];
   $sql = "UPDATE tblemployees SET fullname='$editname', emailadd='$editemail', address='$editaddress', phone='$editphone' WHERE id='$editemployee'";
   if (mysqli_query($conn, $sql)) {
     echo "<script type= 'text/javascript'>alert('Record updated successfully');
  window.location.replace('bootstrap_data_table_with_modal_form.php');</script>";  
   } else {
     echo "<script type= 'text/javascript'>alert('Error updating record: " . $sql . "<br>" . $conn->error."');</script>"; 
   }
}
if ($page==''){
 $page = "1";
}else{
 $page = $_GET['page'];
}
$cur_page = $page;
$page -= 1;
$per_page = 5; 
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
$query_pag_data = "SELECT * from tblemployees LIMIT $start, $per_page";
$result_pag_data = mysqli_query($conn, $query_pag_data);
?>
<div class="container"><div class = "result"></div>
 <p><h1 align="center">Data Table using Mysqli Database and Bootstrap with Modal Form</h1></p>
        <div class="table-wrapper">
            <div class="table-title">
                <div class="row">
                    <div class="col-sm-6">
      <h2>Manage <b>Employees</b></h2>
     </div>
     <div class="col-sm-6">
      <a href="#addEmployeeModal" class="btn btn-success" data-toggle="modal"><i class="material-icons"></i> <span>Add New Employee</span></a>
      <a href="#deleteEmployeeModalselected" class="btn btn-danger" data-toggle="modal"><i class="material-icons"></i> <span>Delete</span></a>      
     </div>
                </div>
            </div>
            <table class="table table-striped table-hover">
                <thead>
     <tr>
      <th>
       <span class="custom-checkbox">
        <input type="checkbox" id="selectAll">
        <label for="selectAll"></label>
       </span>
      </th>
                        <th>Name</th>
                        <th>Email</th>
      <th>Address</th>
                        <th>Phone</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
    while($row = mysqli_fetch_assoc($result_pag_data)) {
     $fullname=$row['fullname']; 
     $emailadd=$row['emailadd']; 
     $address=$row['address']; 
     $phone=$row['phone']; 
    ?>
                    <tr>
      <td>
       <span class="custom-checkbox">
        <input type="checkbox" id="checkbox1" name="options" value="<?php echo $row['id']; ?>">
        <label for="checkbox1"></label>
       </span>
      </td>
                        <td><?php echo $fullname; ?></td>
                        <td><?php echo $emailadd; ?></td>
      <td><?php echo $address; ?></td>
                        <td><?php echo $phone; ?></td>
                        <td>
                            <a href="?editemployee=<?php echo $row['id']; ?>" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>
                            <a href="?deleteemployee=<?php echo $row['id']; ?>" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>
                        </td>
                    </tr>
    <?php } ?> 
                </tbody>
   </table>
   <div class="clearfix">
<?php
$msg = "";
$query_pag_num = mysqli_query($conn,"SELECT COUNT(*) AS mycount FROM tblemployees" ) or die(mysqli_error($this->dblink));
$res = mysqli_fetch_object($query_pag_num);
$count = $res->mycount;
$no_of_paginations = ceil($count / $per_page);
// ---------------Calculating the starting and endign values for the loop----------------------------------- 
if ($cur_page >= 7) {
    $start_loop = $cur_page - 3;
    if ($no_of_paginations > $cur_page + 3)
        $end_loop = $cur_page + 3;
    else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
        $start_loop = $no_of_paginations - 6;
        $end_loop = $no_of_paginations;
    } else {
        $end_loop = $no_of_paginations;
    }
} else {
    $start_loop = 1;
    if ($no_of_paginations > 7)
        $end_loop = 7;
    else
        $end_loop = $no_of_paginations;
}
//----------------------------------------------------------------------------------------------------------- 
$msg .= "<ul class=\"pagination\">";
// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
    $msg .= "<li p='1' class='page-item active'><a href='?page=1' class='page-link'>First</a></li>";
} else if ($first_btn) {
    $msg .= "<li p='1' class='page-item' disabled><a href='?page=1'>First</a></li>";
}
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
    $pre = $cur_page - 1;
    $msg .= "<li p='$pre' class='page-item active'><a href='?page=$pre' class='page-link'>Previous</a></li>";
} else if ($previous_btn) {
    $msg .= "<li class='page-item' disabled><a href='?page=1'>Previous</a></li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
    if ($cur_page == $i)
        $msg .= "<li p='$i' class='page-item active'><a href='?page=$i' class='page-link'>{$i}</a></li>";
    else
        $msg .= "<li p='$i' class='page-item'><a href='?page={$i}' class='page-link'>{$i}</a></li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
    $nex = $cur_page + 1;
    $msg .= "<li p='$nex' class='page-item'><a href='?page=$nex' class='page-link'>Next</a></li>";
} else if ($next_btn) {
    $msg .= "<li class='page-item' disabled><a href='#'>Next</a></li>";
}
// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $msg .= "<li p='$no_of_paginations' class='page-item'><a href='?page=$no_of_paginations' class='page-link'>Last</a></li>";
} else if ($last_btn) {
    $msg .= "<li p='$no_of_paginations' class='page-item' disabled><a href='?page=$no_of_paginations'>Last</a></li>";
}
$total_string = "<div class=\"hint-text\">Showing <b>" . $cur_page . "</b> out of <b>$no_of_paginations</b> entries</div>";
$msg = $msg . "</ul>";  
echo $total_string;
echo $msg;
?>
            </div>   
  </div>
</div> 

<!-- add Modal HTML -->
 <div id="addEmployeeModal" class="modal fade">
  <div class="modal-dialog">
   <div class="modal-content">
    <form action="" method="post">
     <div class="modal-header">      
      <h4 class="modal-title">Add Employee</h4>
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
     </div>
     <div class="modal-body">     
      <div class="form-group">
       <label>Name</label>
       <input type="text" name="fullname" class="form-control" required>
      </div>
      <div class="form-group">
       <label>Email</label>
       <input type="email" name="emailadd" class="form-control" required>
      </div>
      <div class="form-group">
       <label>Address</label>
       <textarea class="form-control" name="address" required></textarea>
      </div>
      <div class="form-group">
       <label>Phone</label>
       <input type="text" name="phone" class="form-control" required>
      </div>     
     </div>
     <div class="modal-footer">
      <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
      <input type="submit" class="btn btn-success" name="cmdaddnew" value="Add">
     </div>
    </form>
   </div>
  </div>
 </div> 
 <!-- Edit Modal HTML -->
 <div id="editEmployeeModal" class="modal fade">
  <div class="modal-dialog">
   <div class="modal-content">
    <form name="frmedit" action="" method="post">
     <div class="modal-header">      
      <h4 class="modal-title">Edit Employee</h4>
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
     </div>
     <div class="modal-body">     
      <div class="form-group">
       <label>Name</label>
       <input type="text" name="editname" value="<?php echo $edit_fullname; ?>" class="form-control" required>
      </div>
      <div class="form-group">
       <label>Email</label>
       <input type="email" name="editemail" value="<?php echo $edit_emailadd; ?>" class="form-control" required>
      </div>
      <div class="form-group">
       <label>Address</label>
       <textarea class="form-control" name="editaddress" required><?php echo $edit_address; ?></textarea>
      </div>
      <div class="form-group">
       <label>Phone</label>
       <input type="text" name="editphone" value="<?php echo $edit_phone; ?>" class="form-control" required>
      </div>     
     </div>
     <div class="modal-footer">
      <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
      <input type="submit" name="cmdedit" class="btn btn-info" value="Save">
     </div>
    </form>
   </div>
  </div>
 </div>
 
 <!-- Delete Modal HTML -->
 <div id="deleteEmployeeModal" class="modal fade">
  <div class="modal-dialog">
   <div class="modal-content">
    <form name="frmdelete" action="" method="post">
     <div class="modal-header">      
      <h4 class="modal-title">Delete Employee</h4>
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
     </div>
     <div class="modal-body">     
      <p>Are you sure you want to delete these Records?</p>
      <p class="text-warning"><small>This action cannot be undone.</small></p>
     </div>
     <div class="modal-footer">
      <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
      <input type="submit" name="cmdelete" class="btn btn-danger" value="Delete">
     </div>
    </form>
   </div>
  </div>
 </div>
 <div id="deleteEmployeeModalselected" class="modal fade">
  <div class="modal-dialog">
   <div class="modal-content">
    <form name="frmdelete" action="" method="post">
     <div class="modal-header">      
      <h4 class="modal-title">Delete Selected Employee</h4>
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
     </div>
     <div class="modal-body">     
      <p>Are you sure you want to all the selected delete Records?</p>
      <p class="text-warning"><small>This action cannot be undone.</small></p>
     </div>
     <div class="modal-footer">
      <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
      <a href="#" id="cmdeleteselected" class="btn btn-danger">Delete</a>
     </div>
    </form>
   </div>
  </div>
 </div>
</body>
</html>      
//ajaxdeleteselected.php
<?php
include"dbcon.php"; 
$selected  = $_POST['selected'];
foreach ($selected as $value) {
 $sql = "DELETE FROM tblemployees WHERE id='$value'";
 if ($conn->query($sql) === TRUE) {
  echo "Record deleted successfully $value <br/>";  
 } else {
  echo "Error deleting record: " . $sql . "<br>" . $conn->error."'"; 
 } 

}
?>

How to create a Jquery Ajax Mysqli Pagenation

Jquery Ajax Pagenation

Create Database table

CREATE TABLE IF NOT EXISTS `paginate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(60) NOT NULL,
  `message` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ; 
 
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jquery ajax pagenation</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $("#results").load("fetch_pages.php", {'page':1} ); //initial page number to load
 $(".paginate_click").click(function (e) {
  $("#results").prepend('<div class="loading-indication"><img src="img/ajax-loader.gif" /> Loading...</div>');
  var page_num = $(this).text(); //get page number from the clicked element 
  $('.paginate_click').removeClass('active'); //remove any active class
  //post page number and load returned data into result element
  $("#results").load("fetch_pages.php", {'page': page_num}, function(){
  });
  $(this).addClass('active'); //add active class to currently clicked element
  return false; //prevent going to herf link
 }); 
});
</script>
</head>
<body>
<?php
include("config.inc.php");
$results = mysqli_query($connecDB,"SELECT COUNT(*) FROM paginate");
$get_total_rows = mysqli_fetch_array($results); //total records
//break total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page); 
//create pagination
if($pages > 1)
{
 $pagination = '';
 $pagination .= '<ul class="paginate">';
 for($i = 1; $i<$pages; $i++)
 {
  $pagination .= '<li><a href="#" class="paginate_click">'.$i.'</a></li>';
 }
 $pagination .= '</ul>';
} 
?>
<p><h1 align="center">How to create a Jquery Ajax Pagenation</h1></p>
<div id="results"></div>
<?php echo $pagination; ?>
<style>
.paginate {
 padding: 0px;
 margin: 0px;
 height: 30px;
 display: block;
 text-align: center;
}
.paginate li {
 display: inline-block;
 list-style: none;
 padding: 0px;
 margin-right: 1px;
 width: 30px;
 text-align: center;
 background: #4CC2AF;
 line-height: 25px;
}
.paginate .active {
 display: inline-block;
 list-style: none;
 padding: 0px;
 margin-right: 1px;
 width: 30px;
 text-align: center;
 line-height: 25px;
 background-color: #666666;
}
.paginate li a{
 color:#FFFFFF;
 text-decoration:none;
}
#results{
font: 12px Arial, Helvetica, sans-serif;
width: 400px;
margin-left: auto;
margin-right: auto;
}
.page_result{
 padding: 0px;
}
.page_result li{
 background: #E4E4E4;
 margin-bottom: 5px;
 padding: 10px;
 font-size: 12px;
 list-style: none;
}
.page_result .page_name {
font-size: 14px;
font-weight: bold;
margin-right: 5px;
}
#results .loading-indication{
 background:#FFFFFF;
 padding:10px;
 position: absolute;
}
</style>
</body>
</html>
//config.inc.php
<?php
$db_username = 'root';
$db_password = '';
$db_name = 'test';
$db_host = 'localhost';
$item_per_page = 5;

$connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
?>
//fetch_pages.php
<?php
include("config.inc.php"); 
//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
//validate page number is really numaric
if(!is_numeric($page_number)){die('Invalid page number!');}
//get current starting point of records
$position = ($page_number * $item_per_page);
//Limit our results within a specified range. 
$results = mysqli_query($connecDB,"SELECT id,name,message FROM paginate ORDER BY id DESC LIMIT $position, $item_per_page");
//output results from database
echo '<ul class="page_result">';
while($row = mysqli_fetch_array($results))
{
 echo '<li id="item_'.$row["id"].'"><span class="page_name">'.$row["name"].'</span><span class="page_message">'.$row["message"].'</span></li>';
}
echo '</ul>';
?>

Jquery Ajax PHP and Mysqli Search Box

Jquery Ajax PHP and Mysqli Search Box

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jquery Ajax PHP and Mysqli Search Box</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(".search_button").click(function() {
    var search_word = $("#search_box").val();
    var dataString = 'search_word='+ search_word;
  if(search_word==''){
  }else{
  $.ajax({
   type: "GET",
   url: "searchdata.php",
   data: dataString,
   cache: false,
   beforeSend: function(html) {
    document.getElementById("insert_search").innerHTML = ''; 
     $("#flash").show();
     $("#searchword").show();
  $(".searchword").html(search_word);
    $("#flash").html('<img src="img/loader.gif" align="absmiddle"> Loading Results...');
     },
  success: function(html){
     $("#insert_search").show();
     $("#insert_search").append(html);
     $("#flash").hide();
  }
  });
  }
  return false;
 });
});
</script>
</head>
<body>
<div align="center">
<div style="width:700px">
<div style="margin-top:20px; text-align:left">
<p align="center"><h1>Jquery Ajax PHP and Mysqli Search Box</h1></p>
<form method="get" action="">
 <input type="text" name="search" id="search_box" class='search_box'/>
 <input type="submit" value="Search" class="search_button" /><br />
 <span style="color:#666666; font-size:14px; font-family:Arial, Helvetica, sans-serif;"><b>Ex :</b> Javascript</span>
</form>
</div>   
<div>
<div id="searchword">Search results for <span class="searchword"></span></div>
<div id="flash"></div>
<ol id="insert_search" class="update"></ol>
</div>
</div>
</div>
<style>
body{
font-family:Arial, Helvetica, sans-serif;
}
a
{
color:#DF3D82;
text-decoration:none
}
a:hover
{
color:#DF3D82;
text-decoration:underline;
}
#search_box{
 padding:3px; border:solid 1px #666666; width:400px; height:45px; font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
}
.search_button{
 height:50px;border:#fe6f41 solid 1px; padding-left:9px;padding-right:9px;padding-top:9px;padding-bottom:9px; color:#000; font-weight:bold; font-size:16px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
}
ol.update{
 list-style:none;font-size:1.1em; margin-top:20px;padding-left:0; 
}
#flash{
 margin-top:20px;
 text-align:left;
}
#searchword{
 text-align:left; margin-top:20px; display:none;
 font-family:Arial, Helvetica, sans-serif;
 font-size:16px;
 color:#000;
}
.searchword{
 font-weight:bold;
 color:#fe6f41;
}
ol.update li{ border-bottom:#dedede dashed 1px; text-align:left;padding-top:10px;padding-bottom:10px;}
ol.update li:first-child{ border-top:#dedede dashed 1px; text-align:left}
</style>
</body>
</html>
//searchdata.php
<?php
include"dbcon.php";
if(isset($_GET['search_word']))
{
 $search_word=$_GET['search_word']; 
 $query = "SELECT * FROM tblprogramming WHERE title LIKE '%".$search_word."%' ORDER BY id DESC LIMIT 20";
 $result = mysqli_query($conn, $query);
 if(mysqli_num_rows($result) > 0) {
  while($row = mysqli_fetch_array($result)){
   $msg = $row["category"];
   $title = $row["title"];
   $bold_word='<b>'.$search_word.'</b>';
   $final_msg = str_ireplace($search_word, $bold_word, $msg);
   echo "<li>$title <br/><span style='font-size:12px;'>$final_msg</span></li>";
  }
  }else{
 echo "<li>No Results</li>";
 } 
}
?>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>

Live Data Search using PHP MySqli and Jquery Ajax

Live Data Search using PHP MySqli and Jquery Ajax
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Data Search using PHP MySqli and Jquery Ajax</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
 load_data();
  function load_data(query)
  {
   $.ajax({
    url:"ajaxlivesearch.php",
    method:"POST",
    data:{query:query},
    success:function(data)
    {
  $('#result').html(data);
    }
   });
  }
  $('#search_text').keyup(function(){
   var search = $(this).val();
   if(search != ''){
    load_data(search);
   }else{
    load_data();
   }
  });
});
</script>
</head>
<body>
<div class="container search-table">
<p><h2 align="center">Live Data Search using PHP MySqli and Jquery Ajax</h2></p>
            <div class="search-box">
                <div class="row">
                    <div class="col-md-3">
                        <h5>Search All Fields</h5>
                    </div>
                    <div class="col-md-9">
                        <input type="text" name="search_text" id="search_text" class="form-control" placeholder="Search all fields e.g. HTML">
                    </div> 
                </div>
            </div>
   <div id="result"></div>
</div>
<style>
.search-table{
    padding: 10%;
    margin-top: -6%;
}
.search-box{
    background: #c1c1c1;
    border: 1px solid #ababab;
    padding: 3%;
}
.search-box input:focus{
    box-shadow:none;
    border:2px solid #eeeeee;
}
.search-list{
    background: #fff;
    border: 1px solid #ababab;
    border-top: none;
}
.search-list h3{
    background: #eee;
    padding: 3%;color:#fe6f41;
    margin-bottom: 0%;
}
</style>
</body>
</html>
//ajaxlivesearch.php
<div class="search-list">
<?php
include"dbcon.php";
$output = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($conn, $_POST["query"]);
 $query = "SELECT * FROM tblprogramming WHERE title LIKE '%".$search."%' OR category LIKE '%".$search."%'";
}else{
 $query = "SELECT * FROM tblprogramming ORDER BY id";
}
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0) {
 $totalfound = mysqli_num_rows($result);
  $output .= '<h3>'.$totalfound.' Records Found</h3>
  <table class="table table-striped custab">
  <thead>
      <tr>
         <th>Title</th>
         <th>Category</th>
      </tr>
  </thead>
  <tbody>';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["title"].'</td>
    <td>'.$row["category"].'</td>
   </tr>';
 }
 echo $output;
}else{
 echo 'No Rocord Found';
}
?>
 </tbody>
   </table>
</div>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
//tablebase table tblprogramming
CREATE TABLE `tblprogramming` (
  `id` int(11) NOT NULL,
  `title` varchar(250) NOT NULL,
  `category` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tblprogramming`
--

INSERT INTO `tblprogramming` (`id`, `title`, `category`) VALUES
(1, 'HTML', 'Web Development'),
(2, 'PHP', 'Web Development'),
(3, 'C#', 'Programming Language'),
(4, 'JavaScript', 'Web Development'),
(5, 'Bootstrap', 'Web Design'),
(6, 'Python', 'Programming Language'),
(7, 'Android', 'App Development'),
(8, 'Angular JS', 'Web Delopment'),
(9, 'Java', 'Programming Language'),
(10, 'Python Django', 'Web Development'),
(11, 'Codeigniter', 'Web Development'),
(12, 'Laravel', 'Web Development'),
(13, 'Wordpress', 'Web Development');

Pagination with PHP and Mysqli

Pagination with PHP and Mysqli
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pagination with PHP and Mysqli</title>
</head>
<body>
<div align="center" style="font-size:24px;color:#cc0000;font-weight:bold">Pagination with PHP and Mysqli</div>
<div id="container">
<?php
$page = (isset($_GET['page']))?$_GET['page']:'';
if ($page==''){
 $page = "1";
}else{
 $page = $_GET['page'];
}
include"dbcon.php";
$cur_page = $page;
$page -= 1;
$per_page = 11; 
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
$msg = "";
$query_pag_data = "SELECT * from country LIMIT $start, $per_page";
$result_pag_data = mysqli_query($conn, $query_pag_data);
while($row = mysqli_fetch_assoc($result_pag_data)) {
 $htmlmsg=htmlentities($row['country']); 
    $msg .= "<li><b>" . $row['id'] . "</b> " . $htmlmsg . "</li>";
}
$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data

$query_pag_num = mysqli_query($conn,"SELECT COUNT(*) AS mycount FROM country" ) or die(mysqli_error($this->dblink));
$res = mysqli_fetch_object($query_pag_num);
$count = $res->mycount;
$no_of_paginations = ceil($count / $per_page);

// ---------------Calculating the starting and endign values for the loop----------------------------------- 
if ($cur_page >= 7) {
    $start_loop = $cur_page - 3;
    if ($no_of_paginations > $cur_page + 3)
        $end_loop = $cur_page + 3;
    else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
        $start_loop = $no_of_paginations - 6;
        $end_loop = $no_of_paginations;
    } else {
        $end_loop = $no_of_paginations;
    }
} else {
    $start_loop = 1;
    if ($no_of_paginations > 7)
        $end_loop = 7;
    else
        $end_loop = $no_of_paginations;
}
//----------------------------------------------------------------------------------------------------------- 
$msg .= "<div class='pagination'><ul>";

// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
    $msg .= "<li p='1' class='active'><a href='?page=1'>First</a></li>";
} else if ($first_btn) {
    $msg .= "<li p='1' class='inactive'><a href='?page=1'>First</a></li>";
}
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
    $pre = $cur_page - 1;
    $msg .= "<li p='$pre' class='active'><a href='?page=$pre'>Previous</a></li>";
} else if ($previous_btn) {
    $msg .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
    if ($cur_page == $i)
        $msg .= "<li p='$i' style='color:#fff;background-color:#70BA4C;' class='active'><a href='?page=$i'>{$i}</a></li>";
    else
        $msg .= "<li p='$i' class='active'><a href='?page={$i}'>{$i}</a></li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
    $nex = $cur_page + 1;
    $msg .= "<li p='$nex' class='active'><a href='?page=$nex'>Next</a></li>";
} else if ($next_btn) {
    $msg .= "<li class='inactive'>Next</li>";
}
// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $msg .= "<li p='$no_of_paginations' class='active'><a href='?page=$no_of_paginations'>Last</a></li>";
} else if ($last_btn) {
    $msg .= "<li p='$no_of_paginations' class='inactive'><a href='?page=$no_of_paginations'>Last</a></li>";
}
$total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
$msg = $msg . "</ul>" . $total_string . "</div>";  // Content for pagination 
echo $msg;
?>
</div>
<style type="text/css">
            body{
                width: 800px;
                margin: 0 auto;
                padding: 0;
            }
   a {text-decoration:none;}
   #container {margin-bottom:20px;}
   #container .data{
    list-style-type: none;
    margin: 0;
    padding: 0;
   }
            #container .data ul li{
                list-style: none;
                background-color:lightyellow;
    border:1px solid #FFDA5B;
    padding:10px;
    margin-bottom:5px;
            }
   #container .data ul li:hover{
                background-color:#70BA4C;
    border:1px solid #448B22;
            }
   #container .data ul li b {
                -moz-border-radius:12px;
    -webkit-border-radius:12px;
    border-radius:32px;
    background-color:#70BA4C;
    border:1px solid #448B22;
    color:#FFFFFF;padding:6px;margin-right:5px;
    text-shadow:1px 1px 0 green;
   }
            #container .pagination ul li.inactive,
            #container .pagination ul li.inactive:hover{
                background-color:#ededed;
                color:#bababa;
                border:1px solid #bababa;
                cursor: default;
            }
            #container .pagination{
                width: 800px;
                height: 25px;
            }
            #container .pagination ul li{
                list-style: none;
                float: left;
                border: 1px solid #006699;
                padding: 4px 8px 4px 8px;
                margin: 0 3px 0 3px;
                font-family: arial;
                font-size: 14px;
                color: #006699;
                font-weight: bold;
                background-color: #f2f2f2;
            }
            #container .pagination ul li:hover{
                color: #fff;
                background-color: #006699;
                cursor: pointer;
            }
   .total
   {
   float:right;font-family:arial;color:#999;
   }
</style>  
</body>
</html>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
Download SQL file Here

Create a PHP jQuery ajax and MySQLi LIKE Search

Create a PHP jQuery ajax and MySQLi LIKE Search






<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create a PHP jQuery ajax and MySQLi LIKE Search</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    $(".search_button").click(function() {
        // getting the value that user typed
        var searchString    = $("#search_box").val();
        // forming the queryString
        var data  = 'search='+ searchString;
        // if searchString is not empty
        if(searchString) {
            // ajax call
            $.ajax({
                type: "POST",
                url: "do_search.php",
                data: data,
                beforeSend: function(html) { // this happens before actual call
                    $("#results").html(''); 
                    $("#searchresults").show();
                    $(".word").html(searchString);
               },
               success: function(html){ // this happens after we get results
                    $("#results").show();
                    $("#results").append(html);
              }
            });    
        }
        return false;
    });
});
</script>
</head>
<body>
<div id="container">
<div style="margin:20px auto; text-align: center;">
<form method="post" action="">
    <input type="text" name="search" id="search_box" class='search_box'/>
    <input type="submit" value="Search" class="search_button" /><br />
</form>
</div>  
<div>
 <div id="searchresults">Search results :</div>
 <div id="results" class="update"></div>
</div>
</div>
<style>
body{ font-family:Arial, Helvetica, sans-serif; }
#container { margin: 0 auto; width: 600px; }
#search_box { 
 padding:4px; 
 border:solid 1px #666666; 
 width:300px; 
 height:30px; 
 font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px; 
}
.search_button { 
 border:#000000 solid 1px; 
 padding: 6px; 
 color:#000; 
 font-weight:bold; 
 font-size:16px;-moz-border-radius: 6px;-webkit-border-radius: 6px; 
}
#searchresults { 
 text-align:left; 
 margin-top:20px; 
 display:none; 
 font-family:Arial, Helvetica, sans-serif; 
 font-size:16px; 
 color:#000;
}
#newspaper-b {
    font-family: lucida sans unicode,lucida grande,Sans-Serif;
    font-size: 12px;
    width: 480px;
    text-align: left;
    border-collapse: collapse;
    border: 1px solid #69c;
    margin: 20px;
}
.tr, tr {
    border-bottom: 1px solid #ddd;
}
#newspaper-b th {
    font-weight: 400;
    font-size: 14px;
    color: #039;
    padding: 15px 10px 10px;
}
#newspaper-b tbody {
    background: #e8edff;
}
#newspaper-b td {
    color: #669;
    border-top: 1px dashed #fff;
    padding: 10px;
}
#newspaper-b tbody tr:hover td{color:#339;background:#d0dafd}
.found { 
 font-weight: bold; 
 font-style: italic; 
 color: #ff0000;
}
</style>
</body>
</html>
//do_search.php
<table id="newspaper-b">
 <thead>
  <tr>
   <th scope="col">Name</th>
   <th scope="col">Category</th>
   <th scope="col">Price</th>
   <th scope="col">Discount</th>
  </tr>
 </thead>
 <tbody>
<?php
include("dbcon.php");
//if we got something through $_POST
if (isset($_POST['search'])) {
    // never trust what user wrote! We must ALWAYS sanitize user input
    $word = mysql_real_escape_string($_POST['search']);
    $word = htmlentities($word);
    // build your search query to the database
 $sql = "SELECT * FROM product WHERE name LIKE '%" . $word . "%' ORDER BY pid LIMIT 10";
 $result = mysqli_query($conn, $sql);
 if (mysqli_num_rows($result) > 0) {
        $end_result = '';
   while($row = mysqli_fetch_assoc($result)) {
   $rs_name = $row["name"];
   $category = $row["category"];
   $price = $row["price"];
   $discount = $row["discount"];
   $bold           = '<span class="found">' . $word . '</span>';    
            $end_result     .= '<tr><td>'. str_ireplace($word, $bold, $rs_name).'</td><td>'.$category.'</td><td>'.$price.'</td><td>'.$discount.'</td></tr>';
  }
        echo $end_result;
 }else {
  echo "0 results";
 }
}
?>
 </tbody>
</table>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>

Create A CSS Administrator Login Form Design and Login system using PHP with MYSQL database

Create A CSS Administrator Login Form Design

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create A CSS Administrator Login Form Design and Login system using PHP with MYSQL database</title>
<style>
#login-form {
	margin:106px auto 0px auto;
	width:560px;
	border:solid 12px #E0E0E0;
	background:#E0E0E0;
	border-radius:12px;
	-moz-border-radius:12px;
	webkit-border-radius:12px;
}
#login-form{
border-color:#4BB2C5;
}
#login-inner {
	border-radius:5px;
	-moz-border-radius:5px;
	webkit-border-radius:5px;
	margin:0 auto;
	padding:30px;
	width:500px;
}
#login-form #wrapper{
	height: 50px;
	border-radius: 8px;
	-moz-border-radius: 8px;
	-webkit-border-radius: 8px;
	text-align:center;
	width:494px;
	margin:0px auto 30px auto;
	font-size:1.2em;
	background-image: url('img/bg.jpg');
}
#login-form #wrapper p{
	padding-top:4px;
	margin:0;
	text-transform:uppercase;
	letter-spacing:2px;
	line-height:2.2em;
	color:#FFF;
	font-weight:bold;
	text-shadow:#111 0px 1px 1px;
}
.field-separator{
	width:560px;
	margin:0px auto 20px auto;
}
#login-form label{
	color:#111;
	display:block;
	font-size:1em;
	margin-bottom:2px;
	font-weight:bold
}
#login-form input.txt {
	background:url('img/login_input_bg.png') repeat-x scroll left top #F7FCFF;
	border:1px solid #CCC;
	color:#25313C;
	font-size:1.4em;
	width:486px;
	padding:4px;
}
#login-form input#login-button{
	text-transform:uppercase;
	float:right;
	margin-top:10px;
	color:#DDD;
}
div#remember-me{
	float:left;
	width:300px;
	margin-top:16px;
}
div#remember-me a{
	color:#000;
	padding-right:10px;
	font-weight:bold;
	font-size:0.75em;
}
#login-bottom{
border-top: 2px dotted #BBB;
padding: 3px;
}
input.submit {
background-color: #111;
}
.submit::selection {
background: transparent;
}
input.submit.large {
padding: 8px 14px 9px;
font-size: 14px;
}
input.submit.round {
border:5px;
border-radius:5px;
-moz-border-radius:5px;
webkit-border-radius:5px;
}
</style>
</head> 
<body style="background:#FEFEFE url('img/bg.jpg') repeat-x;">
<form action="loginsubmit.php" method="post" id="login-form">
     <div id="login-inner">
         <div id="wrapper">
             <p>Administration Login</p>
         </div>
         <div class="field-separator">
             <label for="login">Login</label>
             <input type="text" name="login" value="" id="login" class="txt" />
         </div>
         <div class="field-separator">
             <label for="password">Password</label>
             <input type="password" name="password" value="" id="password" class="txt" />
         </div>
         <div id="login-bottom">
              <div id="remember-me">
                 <a href="#">Remember Me</a>|
                 <a href="#">Forgot Password</a>
			  </div>
             <input type="submit" name="enter" value="Enter" class="submit large round" id="login-button" />
             <div style="clear: both"></div>
         </div>
     </div>
</form>
</body>
</html>
//loginsubmit.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
$username = $_POST['login'];
$pass = $_POST['password'];
$sqlc="SELECT * FROM users WHERE username = '$username' AND password = '$pass'";
if ($rsdc=mysqli_query($conn,$sqlc)){
	$total=mysqli_num_rows($rsdc);
	  if ($total == '1') {
		  echo'<h1>You are a validated user.</h1>';
	  }else{
		echo'<h1>Sorry, your credentials are not valid, Please try again.</h1>';	
	  }		
}	
?>

Create a Jquery/Ajax, php, mysqli - Style suggestion search

Create a Jquery/Ajax, php, mysql - Style suggestion search

Database table

CREATE TABLE IF NOT EXISTS `search` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`img` varchar(255) NOT NULL,
`desc` text NOT NULL,
`url` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create a Jquery/Ajax, php, mysqli - Style suggestion search</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
function find(textboxString) {
	if(textboxString.length == 0) {
		$('#resultbox').fadeOut(); // Hide the resultbox box
	} else {
		$.post("ajaxsuggestdata.php", {queryString: ""+textboxString+""}, function(data) { // Do an AJAX call
			$('#resultbox').fadeIn(); // Show the resultbox box
			$('#resultbox').html(data); // Fill the resultbox box
		});
	}
	// Fade out the resultbox box when not active
	 $("input").blur(function(){
	 	$('#resultbox').fadeOut();
	 });
	 // Safely inject CSS3 and give the search results a shadow
	var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
		'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
		'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
	$("#resultbox").css(cssObj);
}
</script>
</head>
<body>
<div style="margin-left:50px">
	<div><h2>What are you looking for?</h2></div>
	<form id="searchwrapper">
		<div>
			<input type="text" size="30" class="searchbox" value="" id="textboxString" onkeyup="find(this.value);" />
		</div>
		<div id="resultbox"></div>
	</form>
</div>
<style>
	body, div, img, p { padding:0; margin:0; }
	a img { border:0 }
	body { font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif; }
	#searchwrapper {
		width:310px; 
		height:40px;
		background-image:url(img/searchbox.jpg);
		background-repeat:no-repeat; 
		padding:0px;
		margin:0px;
		position:relative; 
	}
	#searchwrapper form { display:inline ; }
	.searchbox {
		border:0px;
		background-color:transparent; 
		position:absolute; 
		top:5px;
		left:9px;
		width:256px;
		height:28px;
		color:#FFFFFF;
	}
	#dbresults { border-width:1px; border-color:#919191; border-style:solid; width:310px;
		font-size:10px; margin-top:20px; -moz-box-shadow:0px 0px 3px #aaa;
		-webkit-box-shadow:0px 0px 3px #aaa;
		box-shadow:0px 0px 3px #aaa;
		-moz-border-radius:5px;
		-webkit-border-radius:5px;
		border-radius:5px;
		padding-top:42px;	
	}
	#dbresults a { display:block; background-color:#D8D6D6; clear:left; height:56px; text-decoration:none; }
	#dbresults a:hover { background-color:#b7b7b7; color:#ffffff; }
	#dbresults a img { float:left; padding:5px 10px; }
	#dbresults a span { color:#555555; }
	#dbresults a:hover span { color:#f1f1f1; }
</style>
</body>
</html>
//ajaxsuggestdata.php
<p id="dbresults">
<?php
	$db = new mysqli('localhost', 'root', '', 'testingdb');
	if(!$db) {
		echo 'ERROR: Could not connect to the database.';
	} else {
		// Is there a posted query string?
		if(isset($_POST['queryString'])) {
			$queryString = $db->real_escape_string($_POST['queryString']);
			// Is the string length greater than 0?
			if(strlen($queryString) >0) {
				$query = $db->query("SELECT * FROM searchs WHERE name LIKE '%" . $queryString . "%' ORDER BY name LIMIT 5");
				
				if($query) {
					while ($result = $query ->fetch_object()) {
						echo '<a href="'.$result->url.'">';
	         			echo '<img src="img/'.$result->img.'" alt="" />';
	         			$description = $result->desc;
	         			if(strlen($description) > 80) { 
	         				$description = substr($description, 0, 80) . "...";
	         			}
	         			echo '<span>'.$description.'</span></a>';
	         		}
	         	} else {
					echo 'ERROR: There was a problem with the query.';
				}
			}else {
				// Dont do anything.
			} // There is a queryString.
		}else {
			echo 'There should be no direct access to this script!';
		}
	}	
?>
</p>