article

Saturday, October 6, 2018

Jquery/Ajax Delete Records show loading image

Jquery/Ajax Delete Records show loading image






<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jquery Ajax Mysql Delete Records show loading image</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#load').hide();
});
$(function() {
 $(".delete").click(function() {
  $('#load').fadeIn();
  var id = $(this).attr("id");
  var string = 'id='+ id ;
  $.ajax({
   type: "POST",
   url: "delete.php",
   data: string,
   cache: false,
   success: function(msg){
   $('#load').fadeOut();
   $("#status").html(msg);
   }
  });
  $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
  .animate({ opacity: "hide" }, "slow");
  return false;
 });
});
</script>
<style>
#hor-minimalist-a
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
background: #fff;
border-collapse: collapse;
text-align: left;
}
#hor-minimalist-a th
{
font-size: 14px;
font-weight: normal;
color: #039;
padding: 10px 8px;
border-bottom: 2px solid #6678b1;
}
#hor-minimalist-a td
{
color: #669;
}
#hor-minimalist-a tbody tr:hover td
{
color: #009;
}
#load {
color:#999;
font-size:18px;
font-weight:300;
}
</style>
</head>
<body>
<div class="container">
 <div class="row">
        <div class="col-md-12">
  <div class="table-responsive">
  
  
<h3>Jquery/Ajax Delete Records Bootstrap for Datatable</h3>
<div id="load" align="left"><img src="img/loader.gif" width="28" height="28" align="absmiddle"/> Loading...</div>
<div id="status"></div>
<table id="hor-minimalist-a" summary="Employee Pay Sheet" class="table table-bordred table-striped">
<thead>
 <tr>
    <th scope="col">Employee</th>
       <th scope="col">Salary</th>
       <th scope="col">Bonus</th>
       <th scope="col">Supervisor</th>
       <th scope="col">Action</th>
   </tr>
</thead>
<tr class="record">
    <td>Stephen C. Cox</td>
       <td>$300</td>
       <td>$50</td>
       <td>Bob</td>
       <td>
  <p><button id="1" class="Edit btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></button>
  <button id="1" class="delete btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></button></p>
    </td>
</tr>
<tr class="record">
    <td>Josephin Tan</td>
       <td>$150</td>
       <td>$400</td>
       <td>Annie</td>
<td><p><button id="2" class="Edit btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></button>
<button id="2" class="delete btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></button></p>
</td>
   </tr>
<tr class="record">
    <td>Caite Ednalan</td>
       <td>$450</td>
       <td>$300</td>
       <td>Batosai</td>
<td><p><button id="7" class="Edit btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></button>
<button id="7" class="delete btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></button></p>
</td>
   </tr>
</table>
<div class="clearfix"></div>
<ul class="pagination pull-right">
  <li class="disabled"><a href="#"><span class="glyphicon glyphicon-chevron-left"></span></a></li>
  <li class="active"><a href="#">1</a></li>
  <li><a href="#">2</a></li>
  <li><a href="#">3</a></li>
  <li><a href="#">4</a></li>
  <li><a href="#">5</a></li>
  <li><a href="#"><span class="glyphicon glyphicon-chevron-right"></span></a></li>
</ul>
  </div>
  </div>
 </div>
</div>
</body>
</html>
//delete.php
<?php
$host = "localhost";
$username_ = "root";
$password = "";
$databasename = "testingdb";
$connect = mysql_connect($host, $username_, $password) or die("Opps some thing went wrong");
mysql_select_db($databasename, $connect) or die("Opps some thing went wrong");

 $id_post = $_POST['id'];
 $sql_user = mysql_query("SELECT * FROM users WHERE id='$id_post'") or die('Invalid query: ' . mysql_error());;
 if(mysql_num_rows($sql_user))
 {
   $sql = "Delete from users WHERE id='$id_post'";
   mysql_query( $sql);
  echo "<div class='btn btn-danger' style='width:100%;'>Record succesfully deleted</div>";
 }else{
  echo "<div class='btn btn-primary' style='width:100%;'>No records found</div>";
 } 

?>

Friday, August 31, 2018

jQuery/Ajax, PHP and Mysql Autosuggest

jQuery/Ajax, PHP and Mysql Autosuggest


Table countries
CREATE TABLE IF NOT EXISTS `countries` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`country` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ;

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery/Ajax, PHP and Mysql Autosuggest </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
function suggest(inputString){
  if(inputString.length == 0) {
   $('#suggestions').fadeOut();
  } else {
   $('#country').addClass('load');
   $.post("data.php", {queryString: ""+inputString+""}, function(data){
    if(data.length >0) {
     $('#suggestions').fadeIn();
     $('#suggestionsList').html(data);
     $('#country').removeClass('load');
    }
   });
  }
}
function fill(thisValue) {
  $('#country').val(thisValue);
  setTimeout("$('#suggestions').fadeOut();", 600);
}
</script>
<style>
#country {
 width:200px;
 padding:3px;
 font-size:110%;
 vertical-align:middle;
}
.suggestionsBox {
 width: 200px;
 color: #fff;
 margin:0;
 padding:0;
 background:#86BAC7;
 top:0;
 left:0;
}
.suggestionList {
 margin: 0px;
 padding: 0px;
}
.suggestionList ul li {
 list-style:none;
 margin: 0px;
 padding: 6px;
 border-bottom:1px dotted #98BE56;
 cursor: pointer;
}
.suggestionList ul li:hover {
 background-color: #006E89;
 color:#000;
}
ul {
 font-family:Arial, Helvetica, sans-serif;
 font-size:11px;
 color:#FFF;
 padding:0;
 margin:0;
}
.load{
background-image:url(img/loader.gif);
background-position:right;
background-repeat:no-repeat;
}
#suggest {
 position:relative;
}
.sf_active{
 border:2px #8BB544 solid;
 background:#fff;
 color:#333;
}
</style>
</head>
<body>
<form id="form" action="#">
 <div id="suggest">Start to type a country: <br />
   <input type="text" size="25" value="" id="country" onkeyup="suggest(this.value);" onblur="fill();" class="sf_active" />
   <div class="suggestionsBox" id="suggestions" style="display: none;">
     <div class="suggestionList" id="suggestionsList">   </div>
   </div>
</div>
</form>
</body>
</html>
//data.php
<?php
   $link = mysql_connect('localhost', 'root', '');
 if (!$link) {
  die('Could not connect: ' . mysql_error());
 }
 mysql_select_db("test");
 if(isset($_POST['queryString'])) {
   $queryString = $_POST['queryString'];
   if(strlen($queryString) >0) {
    $query = mysql_query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");
    if($query) {
    echo '<ul>';
     while ($result = mysql_fetch_array($query)) {
             echo '<li onClick="fill(\''.addslashes($result["country"]).'\');">'.$result["country"].'</li>';
            }
    echo '</ul>';
    } else {
     echo 'OOPS we had a problem :(';
    }
   } else {
   }
 } else {
   echo 'There should be no direct access to this script!';
 }
?> 

Wednesday, August 29, 2018

Create a Jquery/Ajax, php, mysql - 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>

Sunday, August 26, 2018

Create a jquery simple accordion

Create a jquery simple accordion
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create a jquery simple accordion</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('.container').hide();
 $('.accordiontrigger:first').addClass('active').next().show(); //"active" class to first trigger, when click show next container
 $('.accordiontrigger').click(function(){ //On Click
  if( $(this).next().is(':hidden') ) { //next container is closed
   $('.accordiontrigger').removeClass('active').next().slideUp(); //Remove all .accordiontrigger classes and slide up the immediate next container
   $(this).toggleClass('active').next().slideDown(); //Add .accordiontrigger class to clicked trigger and slide down the immediate next container
  }
  return false; //Prevent the browser jump to the link anchor
 });
});
</script>
</head>
<body>
<div class="wrapper">
 <h2 class="accordiontrigger"><a href="">Praesent duis vel similis usitas</a></h2>
 <div class="container">
  <div class="block">
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
  </div>
 </div>
 <h2 class="accordiontrigger"><a href="">hos olim odio olim indoles</a></h2>`
 <div class="container">
  <div class="block">
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
  </div>
 </div> 
 <h2 class="accordiontrigger"><a href="">Euismod, v blandit, jumentum</a></h2>
 <div class="container">
  <div class="block">
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, v blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
  </div>
 </div>
</div>
<style>
body {
 font: 10px normal Arial, Helvetica, sans-serif;
 margin: 0;
 padding: 0;
 line-height: 1.7em;
}
*, * focus {
 outline: none;
 margin: 0;
 padding: 0;
}
.wrapper {
 width: 500px;
 margin: 0 auto;margin-top:50px;
}
h2.accordiontrigger {
 padding: 0; margin: 0 0 5px 0;
 background: url(img/01.gif) no-repeat;
 height: 46px; line-height: 46px;
 width: 500px;
 font-size: 2em;
 font-weight: normal;
 float: left;
}
h2.accordiontrigger a {
 color: #fff;
 text-decoration: none;
 display: block;
 padding: 0 0 0 50px;
}
h2.accordiontrigger a:hover {
 color: #ccc;
}
h2.active {background-position: left bottom;}
.container {
 margin: 0 0 5px; padding: 0;
 overflow: hidden;
 font-size: 1.2em;
 width: 500px;
 clear: both;
 background: #f0f0f0;
 border: 1px solid #d6d6d6;
 -webkit-border-bottom-right-radius: 5px;
 -webkit-border-bottom-left-radius: 5px;
 -moz-border-radius-bottomright: 5px;
 -moz-border-radius-bottomleft: 5px;
 border-bottom-right-radius: 5px;
 border-bottom-left-radius: 5px;
}
.container .block {
 padding: 20px;
}
.container .block p {
 padding: 5px 0;
 margin: 5px 0;
}
.container h3 {
 font: 2.5em normal Georgia, "Times New Roman", Times, serif;
 margin: 0 0 10px;
 padding: 0 0 5px 0;
 border-bottom: 1px dashed #ccc;
}
.container img {
 float: left;
 margin: 10px 15px 15px 0;
 padding: 5px;
 background: #ddd;
 border: 1px solid #ccc;
}
</style>
</body>
</html>

Saturday, August 18, 2018

Jquery Ajax 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>';
?>

Friday, August 17, 2018

Ajax Login with jquery

Ajax Login with jquery mysql and bootstrap

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax Login with jquery mysql and bootstrap</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
 $("#rolling").slideDown('slow');
});
$(document).ready(function(){
  $("#submit").click(function(){
     if($("#uname").val()=="" || $("#pass").val()=="") {
   $(".display").fadeTo('slow','0.99');
   $("msg").hide();
   $(".display").fadeIn('slow',function(){$(".display").html("<span id='error'>Please enter username and password</span>");});
   return false;
     }else{
    $(".display").html('<span class="normal"><img src="img/loader.gif"></span>');
    var uname = $("#uname").val();
    var pass = $("#pass").val();
     $.getJSON("server.php",{username:uname,password:pass},function(json)
     {
      // Parse JSON data if json.response.error = 1 then login successfull
      if(json.response.error == "1")
      {
       $(".display").css('background','#CBF8AF');
       $(".display").css('border-bottom','4px solid #109601');
       data = "<span id='msg'>Welcome "+uname+"</span>";
       window.location.href = "theme_profile.html";
       /*
     login successfull, write code to Show next page here 
       */
      }
      // Login failed
      else
      {
       $(".display").css('background','#FFD9D9');
       $(".display").css('border-bottom','4px solid #FC2607');
       data = "<span id='error'>Error check username and password?</span>";
      }
       $(".display").fadeTo('slow','0.99');
       $(".display").fadeIn('slow',function(){$(".display").html("<span id='msg'>"+data+"</span>");});
     });
    return false;
   }
  });
   $("#uname").focus(function(){
    $(".display").fadeTo('slow','0.0',function(){$(".display").html('');});
   });
   $("#pass").focus(function(){
    $(".display").fadeTo('slow','0.0',function(){$(".display").html('');});
   });
});
</script>
<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>
<!--Fontawesome CDN-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
</head>
<body>
<div class="container">
 <div class="d-flex justify-content-center h-100">
  <div class="card" id="rolling">
   <div class="card-header">
    <h3>Sign In</h3><span id="msg"></span>
    <div class="d-flex justify-content-end social_icon">
     <span><i class="fab fa-facebook-square"></i></span>
     <span><i class="fab fa-google-plus-square"></i></span>
     <span><i class="fab fa-twitter-square"></i></span>
    </div><p class="display"></p> <span id="msg"></span>
   </div>
   <div class="card-body">
   <form name="test" id="test" method="POST">
     <div class="input-group form-group">
      <div class="input-group-prepend">
       <span class="input-group-text"><i class="fas fa-user"></i></span>
      </div>
      <input type="text" name="uname" id="uname" class="form-control" placeholder="username">
     </div>
     <div class="input-group form-group">
      <div class="input-group-prepend">
       <span class="input-group-text"><i class="fas fa-key"></i></span>
      </div>
      <input type="password" name="pass" id="pass" class="form-control" placeholder="password">
     </div>
     <div class="row align-items-center remember">
      <input type="checkbox">Remember Me
     </div>
     <div class="form-group">
      <input type="submit" Value="Login" class="btn float-right login_btn" id="submit">
     </div>
    </form> 
    </div>
     <div class="card-footer">
    <div class="d-flex justify-content-center links">
     Don't have an account?<a href="#">Sign Up</a>
    </div>
    <div class="d-flex justify-content-center">
     <a href="#">Forgot your password?</a>
    </div>
   </div> 
   </div>
  </div>
 </div>
</div>
<style>
@import url('https://fonts.googleapis.com/css?family=Numans');

html,body{
background-image: url('http://getwallpapers.com/wallpaper/full/a/5/d/544750.jpg');
background-size: cover;
background-repeat: no-repeat;
height: 100%;
font-family: 'Numans', sans-serif;
}
.container{
height: 100%;
align-content: center;
}
.card{
height: 370px;
margin-top: auto;
margin-bottom: auto;
width: 400px;
background-color: rgba(0,0,0,0.5) !important;
}
.social_icon span{
font-size: 60px;
margin-left: 10px;
color: #FFC312;
}
.social_icon span:hover{
color: white;
cursor: pointer;
}
.card-header h3{
color: white;
}
.social_icon{
position: absolute;
right: 20px;
top: -45px;
}
.input-group-prepend span{
width: 50px;
background-color: #FFC312;
color: black;
border:0 !important;
}
input:focus{
outline: 0 0 0 0  !important;
box-shadow: 0 0 0 0 !important;
}
.remember{
color: white;
}
.display {color:#fff;}
.remember input
{
width: 20px;
height: 20px;
margin-left: 15px;
margin-right: 5px;
}
.login_btn{
color: black;
background-color: #FFC312;
width: 100px;
}
.login_btn:hover{
color: black;
background-color: white;
}
.links{
color: white;
}
.links a{
margin-left: 4px;
}
</style>
</body>
</html>
//server.php
<?php
$host = "localhost";
$username_ = "root";
$passworddb = "";
$databasename = "testingdb";
$connect = mysql_connect($host, $username_, $passworddb) or die("Opps some thing went wrong");
mysql_select_db($databasename, $connect) or die("Opps some thing went wrong");
$username = $_GET['username'];
$pass = $_GET['password'];
$password = md5($pass);
$sql_check = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'") or die('Invalid query: ' . mysql_error());;
if(mysql_num_rows($sql_check))
{
 echo '{"response":{"error": "1"}}'; // login successfull
}
else
{
  echo '{"response":{"error": "0"}}'; //failed
}
?>

Tuesday, August 7, 2018

Add/Remove Input Fields Dynamically with 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);
}
?>

Friday, August 3, 2018

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);
}
?>

Ajax File Upload with Progress Bar using PHP JQuery

Ajax File Upload with Progress Bar using PHP JQuery


Index.html


<!DOCTYPE html>
 <html>
 <head>
  <title></title>
  <link href="css/bootstrap.min.css" rel="stylesheet" />
  <script src="js/jquery-1.10.2.min.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script src="js/jquery.form.js"></script>
 </head>
 <body>
  <div class="container">
   <br />
   <h3 align="center">Ajax File Upload Progress Bar using PHP JQuery</h3>
   <br />
   <div class="panel panel-default">
    <div class="panel-heading"><b>Ajax File Upload Progress Bar using PHP JQuery</b></div>
    <div class="panel-body">
     <form id="uploadImage" action="upload.php" method="post">
      <div class="form-group">
       <label>File Upload</label>
       <input type="file" name="uploadFile" id="uploadFile" accept=".jpg, .png" />
      </div>
      <div class="form-group">
       <input type="submit" id="uploadSubmit" value="Upload" class="btn btn-info" />
      </div>
      <div class="progress">
       <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
      </div>
      <div id="targetLayer" style="display:none;"></div>
     </form>
     <div id="loader-icon" style="display:none;"><img src="loader.gif" /></div>
    </div>
   </div>
  </div>
 </body>
</html>

<script>
$(document).ready(function(){
 $('#uploadImage').submit(function(event){
  if($('#uploadFile').val())
  {
   event.preventDefault();
   $('#loader-icon').show();
   $('#targetLayer').hide();
   $(this).ajaxSubmit({
    target: '#targetLayer',
    beforeSubmit:function(){
     $('.progress-bar').width('50%');
    },
    uploadProgress: function(event, position, total, percentageComplete)
    {
     $('.progress-bar').animate({
      width: percentageComplete + '%'
     }, {
      duration: 1000
     });
    },
    success:function(){
     $('#loader-icon').hide();
     $('#targetLayer').show();
    },
    resetForm: true
   });
  }
  return false;
 });
});
</script>
upload.php
<?php
//upload.php
if(!empty($_FILES))
{
 if(is_uploaded_file($_FILES['uploadFile']['tmp_name']))
 {
  sleep(1);
  $source_path = $_FILES['uploadFile']['tmp_name'];
  $target_path = 'upload/' . $_FILES['uploadFile']['name'];
  if(move_uploaded_file($source_path, $target_path))
  {
   echo '<img src="'.$target_path.'" class="img-thumbnail" width="300" height="250" />';
  }
 }
}
?>


Download Source Code https://bit.ly/2UX6wZi

Sunday, July 29, 2018

Create a modal box jquery

Create a modal box jquery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create a modal box jquery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
	$('#popupmodal a').bind('click',function(e){
	var $this = $(this);
	$('#overlay').show();
	if(!$('#modal').is(':visible'))
		$('#modal').css('left','-260px')
	   .show()
	   .stop()
	   .animate({'left':'50%'}, 600);
	   e.preventDefault(); //default click prevented
	});

	//clicking on the cross hides the dialog
	$('#modal .close').bind('click',function(){
	   $('#modal').stop()
	   .animate({'left':'150%'}, 600, function(){
	   $(this).hide();
	   $('#overlay').hide();
	   });
	});
});
</script>
</head>
<body>
<div id="overlay" class="overlay" style="display:none;"></div>
<div id="modal" class="modal" style="display:none;">
	<span class="close"></span>
	<h2><img src="img/security.png"/>Login</h2>
	<div class="contents">
	<h1>Login[Quick Form Processing]</h1>
	<form action="" method="POST">
	<p><label style="display: block;">Username:</label><input class="text" type="text" name="username" /></p>
	<p><label style="display: block;">Password:</label><input class="text" type="password" name="password" /></p>
	<p><button class="button" name="login" type="submit">Login</button></p>
	</form>
	<p><a href="#">Forgot password?</a></p>
	</div>
</div>
<div id="popupmodal" style="text-align:center;margin:100px 0px 20px 0px">
	<a href="#"><h1>Click here to popup Login Modal</h1></a>
</div>

<style>
*{
margin:0;
padding:0;
}
body{
font-family:"Myriad Pro",Arial, Helvetica, sans-serif;
overflow-x:hidden;
}
.modal{
position:absolute;
top:25%;
width:450px;
height:300px;
margin-left:-250px;
z-index:9999;
color:#fff;
text-shadow:1px 1px 1px #000;
border:1px solid #303030;
background-color:#212121;
-moz-box-shadow:0px 0px 10px #000;
-webkit-box-shadow:0px 0px 10px #000;
box-shadow:0px 0px 10px #000;
}
.modal h2{
font-weight:100;
padding:5px 0px 5px 5px;
margin:5px;
background-color:#111;
border:1px solid #272727;
}
.modal h2 img{
float:left;
width:28px;
margin-right:10px;
-moz-box-shadow:0px 0px 4px #000;
-webkit-box-shadow:0px 0px 4px #000;
box-shadow:0px 0px 4px #000;
}
span.close{
background:#000 url(img/delete00.png) no-repeat center center;
cursor:pointer;
height:25px;
width:25px;
position:absolute;
right:12px;
top:12px;
cursor:pointer;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
opacity:0.5;
}
span.close:hover{
opacity:1.0;
}
.overlay{
position:fixed;
z-index:999;
top:0px;
left:0px;
width:100%;
height:100%;
background-color:#000;
opacity:0.7;
}
.contents {
padding:10px 10px 10px 45px;
}
.button{
display: inline-block;
float:right;
padding: 4px 10px;
background-color: #1951A5;
color:#fff;
margin:20px;
font-size:12px;
letter-spacing:1px;
text-shadow:1px 1px 1px #011c44;
text-transform:uppercase;
text-decoration: none;
border:1px solid #4c7ecb;
outline:none;
background-image:
-moz-linear-gradient(
top,
rgba(255,255,255,0.25),
rgba(255,255,255,0.05)
);
background-image:
-webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, rgba(255,255,255,0.25)),
color-stop(1, rgba(255,255,255,0.05))
);
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.button:hover{
color: #011c44;
text-shadow: 1px 1px 1px #ccdffc;
}
.button:active{
margin-top:21px;
}
h1{font-weight:normal;font-size:20px;color:#aaaaaa;margin:10 0 10px 0;}
p{font-size: 16px;color: #dedede;margin-top:10px;}
a {color:#729e01;text-decoration:none;}
a:hover{color:#dedede;}
input.text{ border:#ccc 1px solid;-moz-border-radius:7px; -webkit-border-radius:7px;font-size: 20px;width:300px;padding-left:5px;}
</style>
</body>
</html>

Thursday, July 26, 2018

Read XML with jQuery/Ajax


Read XML with jQuery/Ajax


<!DOCTYPE html> <html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Read XML with jQuery/Ajax</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
	$.ajax({
		type: "GET",
		url: "music.xml",
		dataType: "xml",
		success: function_Parsxml
	});
});
function function_Parsxml(xml) {
	$('#load').fadeOut();
	$(xml).find("mostplayedsongs").each(function () {
		$(".main").append('<div class="song"><div class="title">' + $(this).find("Title").text() + '</div> <div class="Artist">' + $(this).find("Artist").text() + '</div></div>');
		$(".song").fadeIn(1000);
	});
}
</script>
<style>
.main{
width:100%;
margin:0 auto;
}
.song{
width:208px;
float:left;
margin:10px;
border:1px #dedede solid;
padding:5px;
display:none;
}
.title{
margin-bottom:6px;}
.Artist{font-size:12px; color:#999; margin-top:4px;}
</style>
</head>
<body>
<div class="main">
	<div align="center" class="loader"><img src="img/loader.gif" id="load" align="absmiddle"/></div>
</div>
</body>
</html>
music.xml
<?xml version="1.0" encoding="utf-8" ?>
<musictype>
<mostplayedsongs>
<Title>Sexyback</Title>
<Artist>Timberlake, Justin</Artist>
</mostplayedsongs>

<mostplayedsongs>
<Title>Wonderful Tonight</Title>
<Artist>Clapton, Eric</Artist>
</mostplayedsongs>

<mostplayedsongs>
<Title> Amazed</Title>
<Artist>Lonestar</Artist>
</mostplayedsongs>

</musictype>

Wednesday, July 25, 2018

PHP Month Array List Select Box

PHP Month Array List Select Box Live-search











<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Month Array List Select Box Live-search</title>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.min.css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
      <h2>PHP Month Array List Select Box Live-search</h2>
      <p>This uses <a href="https://silviomoreto.github.io/bootstrap-select/">https://silviomoreto.github.io/bootstrap-select/</a></p>
      <hr />
    </div>
<?php
$lang_Date = array(
 'Jan'   =>'January',
 'Feb'   =>'February',
 'Mar'   =>'March',
 'Apr'   =>'April',
 'May'   =>'May',
 'June'   =>'June',
 'July'   =>'July',
 'August'  =>'August',
 'Sep'  =>'September',
 'Oct'  =>'October',
 'Nov'  =>'November',
 'Dec'  =>'December',
); 
?>
    <div class="row-fluid">
      <select class="selectpicker" data-show-subtext="true" data-live-search="true">
   <?php
    foreach ($lang_Date as $key=>$value){
  $selected = ($key==$function)?" Selected=\"Selected\"": "";
  echo "<option data-subtext=\"$key\" $selected > $value </option>";
    }
    ?>
      </select>
      <span class="help-inline">Try searching for November</span>
    </div>
  </div>
</body>
</html>

Sunday, July 22, 2018

Jquery Notification Boxes

Jquery Notification Boxes

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Jquery Notification Boxes</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
   $('.notification').hover(function() {
     $(this).css('cursor','pointer');
    }, function() {
     $(this).css('cursor','auto');
   });
   $('.notification span').click(function() {
                $(this).parents('.notification').fadeOut(800);
            });
   
   $('.notification').click(function() {
                $(this).fadeOut(800);
            });
   
});
</script>
</head>

<body>
 <h1>Notification Boxes</h1>
    <div class="notification success">
        <span></span>
        <div class="text">
         <p><strong>Success!</strong> This is a success notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
        </div>
    </div>
 
    <div class="notification warning">
        <span></span>
        <div class="text">
         <p><strong>Warning!</strong> This is a warning notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div>
 
    <div class="notification tip">
        <span></span>
        <div class="text">
         <p><strong>Quick Tip!</strong> This is a quick tip notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div> 
 
 <div class="notification error">
        <span></span>
        <div class="text">
         <p><strong>Error!</strong> This is a error notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
        </div>
    </div>
    
     <div class="notification secure">
        <span></span>
        <div class="text">
         <p><strong>Secure Area!</strong> This is a secure area notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>        
    </div>
    
     <div class="notification info">
        <span></span>
        <div class="text">
         <p><strong>Info!</strong> This is a info notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div>
    
    <div class="notification message">
        <span></span>
        <div class="text">
         <p><strong>Message!</strong> This is a message notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div>
    
    <div class="notification download">
        <span></span>
        <div class="text">
         <p><strong>Download!</strong> This is a download notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div>
   
    <div class="notification purchase">
        <span></span>
        <div class="text">
         <p><strong>Purchase!</strong> This is a purchase notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
        </div>
    </div>
    
    <div class="notification print">
        <span></span>
        <div class="text">
         <p><strong>Print!</strong> This is a print notification. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius eros et risus suscipit vehicula.</p>
     </div>
    </div>
 
</body>
</html>
//css/style.css
body {
 margin: 70px;
 padding: 0;
 background: #e5e5e5;
}

#new {
 margin-bottom: 20px; 
}

h1 {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 18px;
 font-style: normal;
 font-weight: bold;
 color: #323232;
 margin: 50px;
}
/*NOTIFICATION BOX - NO DESCRIPTION */
.notification {
 min-height: 70px;
 width: 580px;
 display: block;
 position: relative;
 /*Border Radius*/
 border-radius: 5px;
 -moz-border-radius: 5px;
 -webkit-border-radius: 5px; 
 /*Box Shadow*/
 -moz-box-shadow: 2px 2px 2px #cfcfcf;
 -webkit-box-shadow: 2px 2px 4px #cfcfcf;
 box-shadow: 2px 2px 2px #cfcfcf;
 margin-bottom: 30px;
}
.notification span {
 background: url(../images/close.png) no-repeat right top;
 display: block;
 width: 19px;
 height: 19px;
 position: absolute;
 top:-9px;
 right: -8px;
}
.notification .text {
 overflow: hidden;
}
.notification p {
 width: 500px; 
 font-family: Arial, Helvetica, sans-serif;
 color: #323232;
 font-size: 14px;
 line-height: 21px;
 text-align: justify;
 float: right;
 margin-right: 15px;
 /* TEXT SHADOW */
  text-shadow: 0px 0px 1px #f9f9f9;
}

/*SUCCESS BOX*/
.success {
 border-top: 1px solid #edf7d0;
 border-bottom: 1px solid #b7e789;
 /*Background Gradients*/
 background: #dff3a8;
 background: -moz-linear-gradient(top,#dff3a8,#c4fb92);
 background: -webkit-gradient(linear, left top, left bottom, from(#dff3a8), to(#c4fb92));
}
.success:before {
 content: url(../images/success.png);
 float: left;
 margin: 23px 15px 0px 15px;
}
.success strong {
 color: #61b316;
 margin-right: 15px;
}

/*WARNING BOX*/
.warning {
 border-top: 1px solid #fefbcd;
 border-bottom: 1px solid #e6e837;
 /*Background Gradients*/
 background: #feffb1;
 background: -moz-linear-gradient(top,#feffb1,#f0f17f);
 background: -webkit-gradient(linear, left top, left bottom, from(#feffb1), to(#f0f17f));
}
.warning:before {
 content: url(../images/warning.png);
 float: left;
 margin: 15px 15px 0px 25px;
}
.warning strong {
 color: #e5ac00;
 margin-right: 15px;
}

/*QUICK TIP BOX*/
.tip {
 border-top: 1px solid #fbe4ae;
 border-bottom: 1px solid #d9a87d;
 /*Background Gradients*/
 background: #f9d9a1;
 background: -moz-linear-gradient(top,#f9d9a1,#eabc7a);
 background: -webkit-gradient(linear, left top, left bottom, from(#f9d9a1), to(#eabc7a));
}
.tip:before {
 content: url(../images/tip.png);
 float: left;
 margin: 20px 15px 0px 15px;
}
.tip strong {
 color: #b26b17;
 margin-right: 15px;
}
/*ERROR BOX*/
.error {
 border-top: 1px solid #f7d0d0;
 border-bottom: 1px solid #c87676;
 /*Background Gradients*/
 background: #f3c7c7;
 background: -moz-linear-gradient(top,#f3c7c7,#eea2a2);
 background: -webkit-gradient(linear, left top, left bottom, from(#f3c7c7), to(#eea2a2));
}
.error:before {
 content: url(../images/error.png);
 float: left;
 margin: 20px 15px 0px 15px;
}
.error strong {
 color: #b31616;
 margin-right: 15px;
}
/*SECURE AREA BOX*/
.secure {
 border-top: 1px solid #efe0fe;
 border-bottom: 1px solid #d3bee9;
 /*Background Gradients*/
 background: #e5cefe;
 background: -moz-linear-gradient(top,#e5cefe,#e4bef9);
 background: -webkit-gradient(linear, left top, left bottom, from(#e5cefe), to(#e4bef9));
}
.secure:before {
 content: url(../images/secure.png);
 float: left;
 margin: 18px 15px 0px 15px;
}
.secure strong {
 color: #6417b2;
 margin-right: 15px;
}
/*INFO BOX*/
.info {
 border-top: 1px solid #f3fbff;
 border-bottom: 1px solid #bedae9;
 /*Background Gradients*/
 background: #e0f4ff;
 background: -moz-linear-gradient(top,#e0f4ff,#d4e6f0);
 background: -webkit-gradient(linear, left top, left bottom, from(#e0f4ff), to(#d4e6f0));
}
.info:before {
 content: url(../images/info.png);
 float: left;
 margin: 18px 15px 0px 21px;
}
.info strong {
 color: #177fb2;
 margin-right: 15px;
}
/*MESSAGE BOX*/
.message {
 border-top: 1px solid #f4f4f4;
 border-bottom: 1px solid #d7d7d7;
 
 /*Background Gradients*/
 background: #f0f0f0;
 background: -moz-linear-gradient(top,#f0f0f0,#e1e1e1);
 background: -webkit-gradient(linear, left top, left bottom, from(#f0f0f0), to(#e1e1e1));
}
.message:before {
 content: url(../images/message.png);
 float: left;
 margin: 25px 15px 0px 15px;
}
.message strong {
 color: #323232;
 margin-right: 15px;
}
/*DONWLOAD BOX*/
.download {
 border-top: 1px solid #ffffff;
 border-bottom: 1px solid #eeeeee;
 
 /*Background Gradients*/
 background: #f7f7f7;
 background: -moz-linear-gradient(top,#f7f7f7,#f0f0f0);
 background: -webkit-gradient(linear, left top, left bottom, from(#f7f7f7), to(#f0f0f0));
}

.download:before {
 content: url(../images/download.png);
 float: left;
 margin: 16px 15px 0px 18px;
}

.download strong {
 color: #037cda;
 margin-right: 15px;
}

/*PURCHASE BOX*/

.purchase {
 border-top: 1px solid #d1f7f8;
 border-bottom: 1px solid #8eabb1;
 
 /*Background Gradients*/
 background: #c4e4e4;
 background: -moz-linear-gradient(top,#c4e4e4,#97b8bf);
 background: -webkit-gradient(linear, left top, left bottom, from(#c4e4e4), to(#97b8bf));
}

.purchase:before {
 content: url(../images/purchase.png);
 float: left;
 margin: 19px 15px 0px 15px;
}

.purchase strong {
 color: #426065;
 margin-right: 15px;
}

/*PRINT BOX*/

.print {
 border-top: 1px solid #dde9f3;
 border-bottom: 1px solid #8fa6b2;
 
 /*Background Gradients*/
 background: #cfdde8;
 background: -moz-linear-gradient(top,#cfdde8,#9eb3bd);
 background: -webkit-gradient(linear, left top, left bottom, from(#cfdde8), to(#9eb3bd));
}

.print:before {
 content: url(../images/print.png);
 float: left;
 margin: 19px 15px 0px 15px;
}

.print strong {
 color: #3f4c6b;
 margin-right: 15px;
}

Download Source Code and Images

Ajax Image Upload using PHP and jQuery

Ajax Image Upload using PHP and jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax Image Upload using PHP and jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function (e) {
$("#uploadimage").on('submit',(function(e) {
 e.preventDefault();
 $("#message").empty();
 $('#loading').show();
 $.ajax({
  url: "ajax_php_file.php", // Url to which the request is send
  type: "POST",             // Type of request to be send, called as method
  data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
  contentType: false,       // The content type used when sending data to the server.
  cache: false,             // To unable request pages to be cached
  processData:false,        // To send DOMDocument or non processed data file it is set to false
  success: function(data)   // A function to be called if request succeeds
  {
   $('#loading').hide();
   $("#message").html(data);
  }
 });
}));

// Function to preview image after validation
$(function() {
 $("#file").change(function() {
  $("#message").empty(); // To remove the previous error message
  var file = this.files[0];
  var imagefile = file.type;
  var match= ["image/jpeg","image/png","image/jpg"];
  if(!((imagefile==match[0]) || (imagefile==match[1]) || (imagefile==match[2])))
  {
   $('#previewing').attr('src','img/noimage.png');
   $("#message").html("<p id='error'>Please Select A valid Image File</p>"+"<h4>Note</h4>"+"<span id='error_message'>Only jpeg, jpg and png Images type allowed</span>");
   return false;
  }
  else
  {
   var reader = new FileReader();
   reader.onload = imageIsLoaded;
   reader.readAsDataURL(this.files[0]);
  }
 });
});
function imageIsLoaded(e) {
 $("#file").css("color","green");
 $('#image_preview').css("display", "block");
 $('#previewing').attr('src', e.target.result);
 $('#previewing').attr('width', '250px');
 $('#previewing').attr('height', '230px');
};
});
</script>
</head>
<body>
<div class="main">
<h1>Ajax Image Upload</h1><br/>
<hr>
<form id="uploadimage" action="" method="post" enctype="multipart/form-data">
<div id="image_preview"><img id="previewing" src="img/noimage.png"/></div>
<hr id="line">
<div id="selectImage">
<label>Select Your Image</label><br/>
<input type="file" name="file" id="file" required />
<input type="submit" value="Upload" class="submit" />
</div>
</form>
</div>
<h4 id='loading'><img id="previewing" src="img/loader.gif"/> Loading..</h4>
<div id="message"></div>
<style>
body {
font-family: 'Roboto Condensed', sans-serif;
}
h1
{
text-align: center;
background-color: #FEFFED;
height: 70px;
color: rgb(95, 89, 89);
margin: 0 0 -29px 0;
padding-top: 14px;
border-radius: 10px 10px 0 0;
font-size: 35px;
}
.main {
position: absolute;
top: 50px;
left: 20%;
width: 450px;
height:530px;
border: 2px solid gray;
border-radius: 10px;
}
.main label{
color: rgba(0, 0, 0, 0.71);
margin-left: 60px;
}
#image_preview{
width:100%;
height:auto;
text-align: center;
color: #C0C0C0;
overflow: auto;
}
#selectImage{
padding: 19px 21px 14px 15px;
position: absolute;
bottom: 0px;
width: 414px;
background-color: #FEFFED;
border-radius: 10px;
}
.submit{
font-size: 16px;
background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
border: 1px solid #e5a900;
color: #4E4D4B;
font-weight: bold;
cursor: pointer;
width: 300px;
border-radius: 5px;
padding: 10px 0;
outline: none;
margin-top: 20px;
margin-left: 15%;
}
.submit:hover{
background: linear-gradient(#ffdd7f 5%, #ffbc00 100%);
}
#file {
color: red;
padding: 5px;
border: 5px solid #8BF1B0;
background-color: #8BF1B0;
margin-top: 10px;
border-radius: 5px;
box-shadow: 0 0 15px #626F7E;
margin-left: 15%;
width: 72%;
}
#message{
position:absolute;
top:120px;
left:815px;
}
#success
{
color:green;
}
#invalid
{
color:red;
}
#line
{
margin-top: 274px;
}
#error
{
color:red;
}
#error_message
{
color:blue;
}
#loading
{
display:none;
position:absolute;
top:50px;
left:850px;
font-size:25px;
}
</style>
</body>
</html>
<?php
if(isset($_FILES["file"]["type"]))
{
 $validextensions = array("jpeg", "jpg", "png");
 $temporary = explode(".", $_FILES["file"]["name"]);
 $file_extension = end($temporary);
 if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")
 ) && ($_FILES["file"]["size"] < 100000)//Approx. 100kb files can be uploaded.
 && in_array($file_extension, $validextensions)) {
  if ($_FILES["file"]["error"] > 0){
   echo "Return Code: " . $_FILES["file"]["error"] . "<br/><br/>";
  }else{
   if (file_exists("upload/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " <span id='invalid'><b>already exists.</b></span> ";
   }else{
    $sourcePath = $_FILES['file']['tmp_name']; // Storing source path of the file in a variable
    $targetPath = "upload/".$_FILES['file']['name']; // Target path where file is to be stored
    move_uploaded_file($sourcePath,$targetPath) ; // Moving Uploaded file
    echo "<span id='success'>Image Uploaded Successfully...!!</span><br/>";
    echo "<br/><b>File Name:</b> " . $_FILES["file"]["name"] . "<br>";
    echo "<b>Type:</b> " . $_FILES["file"]["type"] . "<br>";
    echo "<b>Size:</b> " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "<b>Temp file:</b> " . $_FILES["file"]["tmp_name"] . "<br>";
   }
  }
 }else{
  echo "<span id='invalid'>***Invalid file Size or Type***<span>";
 }
}
?>

Thursday, July 19, 2018

Bootstrap Drop Down Sub Menu

Bootstrap Drop Down Sub Menu

A simple way to show navbar submenus on hover in Bootstrap 4
<!DOCTYPE html>
<html >
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Drop Down Sub Menu</title>
  <base target="_self">
  <meta name="description" content="A simple way to show navbar submenus on hover in Bootstrap 4" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
  <style type="text/css">.navbar-nav li:hover > ul.dropdown-menu {
    display: block;
}
.dropdown-submenu {
    position:relative;
}
.dropdown-submenu>.dropdown-menu {
    top:0;
    left:100%;
    margin-top:-6px;
}
/* rotate caret on hover */
.dropdown-menu > li > a:hover:after {
    text-decoration: underline;
    transform: rotate(-90deg);
} 
</style>
</head>
<body >
  <nav class="navbar navbar-expand-md navbar-light bg-light">
  <a class="navbar-brand pb-2" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <li><a class="dropdown-item" href="#">Action</a></li>
          <li><a class="dropdown-item" href="#">Another action</a></li>
          <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="http://google.com">Google</a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Submenu</a></li>
              <li><a class="dropdown-item" href="#">Submenu0</a></li>
              <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="#">Submenu 1</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                  <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                </ul>
              </li>
              <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="#">Submenu 2</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                  <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</nav>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>

Using Stripe with PHP

Using Stripe with PHP

1. Setup the PHP SDK

We are going to use the Stripe PHP download on Github from Stripe.

2. HTML code index.html



<html>
<head>
<title>stripe php</title>
<style>
.StripeElement {
    background-color: white;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    box-shadow: 0 1px 3px 0 #e6ebf1;
    -webkit-transition: box-shadow 150ms ease;
    transition: box-shadow 150ms ease;
}
.StripeElement--focus {
    box-shadow: 0 1px 3px 0 #cfd7df;
}
.StripeElement--invalid {
    border-color: #fa755a;
}
.StripeElement--webkit-autofill {
    background-color: #fefde5 !important;
}
</style>
</head>
<body>
<form action="charge.php" method="post" id="payment-form">
  <div class="form-row">
    <label for="card-element">Credit or debit card</label>
    <div id="card-element">
      <!-- a Stripe Element will be inserted here. -->
    </div>
    <!-- Used to display form errors -->
    <div id="card-errors"></div>
  </div>
  <button>Submit Payment</button>
</form>
<!-- The needed JS files -->
<!-- JQUERY File -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Stripe JS -->
<script src="https://js.stripe.com/v3/"></script>
<!-- Your JS File -->
<script src="charge.js"></script>
</body>
</html>
3. charge.js file
// Stripe API Key
var stripe = Stripe('pk_test_Agw01Kg5ZpIuuzUwR8tGLUME'); //YOUR_STRIPE_PUBLISHABLE_KEY
var elements = stripe.elements();
// Custom Styling
var style = {
    base: {
        color: '#32325d',
        lineHeight: '24px',
        fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
        fontSmoothing: 'antialiased',
        fontSize: '16px',
        '::placeholder': {
            color: '#aab7c4'
        }
    },
    invalid: {
        color: '#fa755a',
        iconColor: '#fa755a'
    }
};
// Create an instance of the card Element
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
    var displayError = document.getElementById('card-errors');
if (event.error) {
        displayError.textContent = event.error.message;
    } else {
        displayError.textContent = '';
    }
});
// Handle form submission
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
    event.preventDefault();
stripe.createToken(card).then(function(result) {
        if (result.error) {
            // Inform the user if there was an error
            var errorElement = document.getElementById('card-errors');
            errorElement.textContent = result.error.message;
        } else {
            stripeTokenHandler(result.token);
        }
    });
});
// Send Stripe Token to Server
function stripeTokenHandler(token) {
    // Insert the token ID into the form so it gets submitted to the server
    var form = document.getElementById('payment-form');
// Add Stripe Token to hidden input
    var hiddenInput = document.createElement('input');
    hiddenInput.setAttribute('type', 'hidden');
    hiddenInput.setAttribute('name', 'stripeToken');
    hiddenInput.setAttribute('value', token.id);
    form.appendChild(hiddenInput);
// Submit form
    form.submit();
}
4. charge.php file
<?php
require_once('/stripe-php-6.10.3/init.php');
\Stripe\Stripe::setApiKey('sk_test_mnT9JSEucLntq5fFi5hdNlce'); //YOUR_STRIPE_SECRET_KEY
// Get the token from the JS script
$token = $_POST['stripeToken'];
// This is a $20.00 charge in US Dollar.
//Charging a Customer
// Create a Customer
$name_first = "Batosai";
$name_last = "Ednalan";
$address = "New Cabalan Olongapo City";
$state = "Zambales";
$zip = "22005";
$country = "Philippines";
$phone = "09306408219";
$user_info = array("First Name" => $name_first, "Last Name" => $name_last, "Address" => $address, "State" => $state, "Zip Code" => $zip, "Country" => $country, "Phone" => $phone);
$customer = \Stripe\Customer::create(array(
    "email" => "rednalan23@gmail.com",
    "source" => $token,
 'metadata' => $user_info,
));
// Save the customer id in your own database!
// Charge the Customer instead of the card
$charge = \Stripe\Charge::create(array(
    "amount" => 2000,
 "description" => "Purchase off Caite watch",
    "currency" => "usd",
    "customer" => $customer->id,
 'metadata' => $user_info
));
print_r($charge);
// You can charge the customer later by using the customer id.

//Making a Subscription Charge
// Get the token from the JS script
//$token = $_POST['stripeToken'];
// Create a Customer
//$customer = \Stripe\Customer::create(array(
//    "email" => "paying.user@example.com",
//    "source" => $token,
//));
// or you can fetch customer id from the database too.
// Creates a subscription plan. This can also be done through the Stripe dashboard.
// You only need to create the plan once.
//$subscription = \Stripe\Plan::create(array(
//    "amount" => 2000,
//    "interval" => "month",
//    "name" => "Gold large",
//    "currency" => "cad",
//    "id" => "gold"
//));
// Subscribe the customer to the plan
//$subscription = \Stripe\Subscription::create(array(
//    "customer" => $customer->id,
//    "plan" => "gold"
//));
//print_r($subscription);
?>

Sunday, July 15, 2018

Create a JavaScript All Check Radio Buttons

Create a JavaScript All Check Radio Buttons





<html>
<head>
</head>
<body>
<script>
 function checkall(formname,checkname,thestate){
 var el_collection=eval("document.forms."+formname+"."+checkname)
 for (c=0;c<el_collection.length;c++)
 el_collection[c].checked=thestate
 }
</script>
<form name="test">
<input type="checkbox" name="v1"> Peter<br />
<input type="checkbox" name="v1"> Jane<br />
<input type="checkbox" name="v1"> George<br />
<input type="checkbox" name="v1"> Ednalan<br />
</form>
<a href="javascript:checkall('test','v1',true)">Check All</a><br />
<a href="javascript:checkall('test','v1',false)">Uncheck All</a>
</body>
</html>

Manage Table Add Edit Delete jquery ajax mysqli

Manage Table Add Edit Delete jquery ajax mysqli

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Table Add Edit Delete jquery ajax mysqli</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
function deleteuser(id){
 if (confirm('Are you sure want to delete?')) {
 $.post('manage_functions.php', {id: +id, action: 'delete_user'},
 function(response){
  $("#row_"+id).fadeOut("slow");
  $(".info_message").html(response);
  $(".info_message").animate({opacity : '0.9'}).fadeIn().delay(3000).fadeOut(1000);
   });
 }
}
function edituser(id){
 $.post('manage_functions.php', {id: +id, action: 'edit_user'},
    function(response){
      $(".edit_user").html(response);
 });
}
$(document).ready( function () {
  $('tr').hover( function () {
   $(this).toggleClass('tr-hover');
  });
  
  $('#Register').click(function () {
        var str = $('#register_form').serialize();
        $.ajax({
            type: "POST",
            url: "register.php",
            data: str,
            success: function (msg) {
                if (msg.length == "") {
     $('.registration_error').html("You Have Successfully Registered.")
     .fadeIn()
     .delay(3000)
     .slideUp();
     $('.registration_box_wrap,.registration_box').delay(1500).fadeOut();
                } else {
                      $('.registration_error').html(msg)
      .fadeIn()
      .delay(3000)
      .slideUp();
                }
            }
        });
  return false;
    });
 $('.register').click(function () {
        $('.registration_box_wrap').fadeIn(500);
        $('.registration_box').fadeIn(200);
  return false;
    });
 $('.cancel').click(function () {
        $('.registration_box_wrap').fadeOut(500);
        $('.registration_box').fadeOut(200);
  return false;
    });
});
</script>
</head>
<body>
<div class="main">
<a class='register' href="" id="button">Add New User</a> 
<div class="edit_user"></div>
<table width="587" border="0" align="center" cellpadding="5" cellspacing="0">
  <thead>
    <tr>
      <th width="35">ID</th>
      <th>User Name</th>
      <th>Email</th>
      <th>Registration Date</th>
      <th width="130">Actions</th>
    </tr>
  </thead>
  <tbody>
<?php
include("dbcon.php");
$sql = $conn->query("SELECT * from users");
while($row = $sql->fetch_assoc()) {
?>
    <tr id="row_<?php echo $row['id']; ?>">
       <td><?php echo $row['id']; ?></td>
       <td><?php echo $row['username']; ?></td>
       <td><?php echo $row['email']; ?></td> 
       <td><?php echo $row['reg_date']; ?></td>
       <td><a href="#" id="button" onclick="edituser(<?php echo $row['id']; ?>)">Edit</a>
   <a href="#" id="button"  onclick="deleteuser(<?php echo $row['id']; ?>)"> Delete</a>
       </td>
 </tr>
<?php }  ?>
  </tbody></table>
</div>
<div class="registration_box" style="display:none;">
 <h2>Register</h2>
  <div class="registration_error" style="display:none;"></div>
  <form id="register_form" name="form1" method="post" action="">
    Username<br />
    <input type="text" name="username" id="username" />
    <br />
    Password<br />
    <input type="password" name="password" id="textfield2" />
    <br />
    Email<br />
    <input type="text" name="email" id="email" />
    <br />
    <br />
    <input type="submit" name="Register" id="Register" value="Register" />
  or <a class="cancel" href="#">cancel</a>
  </form>
</div>

<div class="registration_box_wrap"  style="display:none;"></div>
<div class="info_message" style="display:none;"></div>
<style type="text/css">
table thead tr th {
 background-color: #FFF;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 border-bottom-color: #CCC;
 padding: 4px;
 color: #000;
 border-right-width: 1px;
 border-right-style: solid;
 border-right-color: #CCC;
 font-size: 12px;
}
table {
 background-color: #FFF;
 color: #333;
 float: left;
 position: absolute;
 top: 100px;
 width: 652px;
}
td a {
 color: #333;
 display: block;
 float: left;
 padding: 4px;
 text-decoration: none;
 font-size: 18px;
}
td {
 border-right-width: 1px;
 border-right-style: solid;
 border-right-color: #CCC;
 padding: 5px;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 border-bottom-color: #CCC;
}
.tr-hover {
 background-color: #eeeeee;
}
.main {
 width: 700px;
 margin-top: 50px;
 margin-right: auto;
 margin-left: auto;
}
body {
 background-color: #efefef;
 font-family: Arial, Helvetica, sans-serif;
 margin: 0px;
 padding: 0px;
 height: 100%;
 width: 100%;
}
#button {
 padding: 5px;
 display: block;
 float: left;
 background-color: #ffffff;
 border: 1px solid #CCC;
 color: #666;
 text-decoration: none;
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;
 margin-top: 3px;
 margin-right: 3px;
 margin-bottom: 3px;
}
.registration_box {
 background-color: #EEE;
 height: auto;
 width: 250px;
 margin-top: 75px;
 margin-right: auto;
 margin-left: auto;
 border: 5px solid #CCC;
 z-index: 999;
 -webkit-border-radius: 5px;
 -moz-border-radius: 5px;
 border-radius: 5px;
 filter:alpha(opacity=100);
 -moz-opacity:1;
 -khtml-opacity: 1;
 opacity: 1;
 position: relative;
 padding: 20px;
 color: #333;
 font-family: Arial, Helvetica, sans-serif;
}
.registration_box_wrap {
 z-index: 888;
 height: 100%;
 width: 100%;
 background-color: #333;
 position: absolute;
 filter:alpha(opacity=50);
 -moz-opacity:0.5;
 -khtml-opacity: 0.5;
 opacity: 0.5;
 top: 0px;
}
.edit_user {
 text-align: center;
 padding: 10px;
}
.info_message {
 text-align: center;
 margin: 10px;
 background-color: #EEE;
 font-family: Arial, Helvetica, sans-serif;
 padding: 10px;
 font-size: 18px;
 float: left;
 position: absolute;
 left: 5px;
 top: 5px;
}
.registration_error {
 font-size: 14px;
 padding: 5px;
 border: thin solid #09F;
 margin: 5px;
 text-align: center;
}
</style>
</body>
</html>
//dbcon.php
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
?>
//register.php
<?php
include("dbcon.php");
$username = $_POST['username'];
$password = $_POST['password'];
$email    = $_POST['email'];
#Create a unique code which will be used to confirm user accounts.
$confirm_code = md5(rand(0,99999).rand(0,999999));
#Check if data is of required lenght.
if (strlen($username) < 3 || strlen($password) < 3 || strlen($email) < 3)
{
 die("All Fields Must Be At Least 3 Characters");
}
if (!preg_match('/^[a-zA-Z0-9&\'\.\-_\+]+\@[a-zA-Z0-9.-]+\.+[a-zA-Z]{2,6}$/', $email)) { 
 die("Email Address Not Vaild.");
}
#Check if username or email is already in use.
$password = md5($password);
$sqlc="SELECT * FROM users WHERE username = '$username' OR email = '$email'";
if ($rsdc=mysqli_query($conn,$sqlc)){
  $total=mysqli_num_rows($rsdc); 
  if ($total >= '1') {
   die("Username Or Email Already In Use"); 
  } 
}
$sql = "INSERT INTO users (username,password,email,confirm_code,reg_date)
VALUES ('$username', '$password', '$email', '$confirm_code', now())";
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
//manage_functions.php
<?php
include("dbcon.php");
if ($_POST['action'] == 'delete_user') {
  $id = $_POST['id'];
  $sql = "DELETE FROM users WHERE id=$id";
 if ($conn->query($sql) === TRUE) {
  echo "Record deleted successfully";
 } else {
  echo "Error deleting record: " . $conn->error;
 } 
}else if ($_POST['action'] == 'edit_user') {
 $id = $_POST['id'];
   $sql = "SELECT * FROM users WHERE id = $id";
    $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
 
?><script>
  $(document).ready(function(){
   $("#edit_user_button").click(function(){
     var str = $('#edit_user_form').serialize();
    $.ajax({
     type: "POST",
     url: "manage_functions.php",
     data: str,
     success: function (msg) { 
      $('.info_message').html(msg).fadeIn().delay(3000).fadeOut();
      $('.edit_user').hide(500);
     }
    });
    return false; 
   });
  });
  </script>
   <form id="edit_user_form" name="edit_user_form" method="post" action="">
  Uname: 
  <input name="username" type="text" id="username" value="<?php echo $row["username"]; ?>" /> 
  Email: 
  <input name="email" type="text" id="email" value="<?php echo $row["email"]; ?>" />
  <input name="id" type="hidden" id="id" value="<?php echo $row["id"]; ?>">
  <input name="action" type="hidden" id="id" value="save_user_info">
  <input type="button" name="button" id="edit_user_button" value="Edit User" />
   </form>
<?php
}else if ($_POST['action'] == 'save_user_info') {
   $id =   $_POST['id'];
   $username = $_POST['username'];
   $email =  $_POST['email'];
   $sql = "UPDATE users SET username = '$username', email= '$email' WHERE id = '$id' ";
  if ($conn->query($sql) === TRUE) {
   echo "User Successfully Edited";
  } else {
   echo "Error updating record: " . $conn->error;
  }
}
?>   

Saturday, July 14, 2018

Javascript Disable button Terms and Conditions

Javascript Disable button Terms and Conditions

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript Disable button Terms and Conditions</title>
<script language=javascript>
function apply()
{
 document.frm.sub.disabled=true;
 if(document.frm.chk.checked==true)
 {
   document.frm.sub.disabled=false;
 }
 if(document.frm.chk.checked==false)
 {
   document.frm.sub.enabled=false;
 }
}
</script>
</head>
<body>
<form name="frm">
<table style="border:solid green 1px">
<tr><td align=center>I agree Terms and Conditions <input type="checkbox" name="chk" onClick="apply()"></td></tr>
<tr><td align=center><input type="button" name="sub" value="submit" disabled></td></tr>
</table>
</form>
</body>
</html>

Related Post