Posts

Showing posts from 2017

phone no validation

< form > Phone Number (format: xxx-xxx-xxxx): < input type = "tel" pattern = "^\d {3} -\d {3} -\d {4} $" required > < input type = "submit" value = "Submit" > </ form > < form > Phone Number (format: xxxxxxxxxx): < input type = "tel" pattern = "^\d {10} $" required > < input type = "submit" value = "Submit" > </ form >

Javascript onkeyup

<html>     <head>         <script>             function add()             {                 var a = parseInt(document.getElementById("t1").value);                 var b = parseInt(document.getElementById("t2").value);                 var result = a + b;                 document.getElementById("s1").innerHTML = result;             }         </script>         <title>Addition Using Ajax</title>     </head>     <body>         <h1>Addition Using Ajax </h1>         <table border="0" cellpadding="10px">             <tr>                 <td>Enter First Number</td>                 <td>                     <input type="text" id="t1" onKeyUp="add()">                 </td>             </tr>             <tr>                 <td>Enter Second Number</td>                 <td>                 

Display records from database using pie chart

<?php $con=mysqli_connect('localhost','root','root','pie_chart') or die(mysqli_connect_error());    $query=mysqli_query($con,"select * from visitors") or die(mysqli_error($con));  ?> <html>   <head>     <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>     <script type="text/javascript">       google.charts.load('current', {'packages':['corechart']});       google.charts.setOnLoadCallback(drawChart);       function drawChart() {         var data = google.visualization.arrayToDataTable([           ['country', 'Visits'],           <?php           while ($row=mysqli_fetch_assoc($query)) {                             echo "['".$row['country']."',".$row['vis']."],";           }            ?>         ]);         var o

Difference between two dates

<!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>Untitled Document</title> </head> <body> <!-- daterange picker -->   <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">   <!-- bootstrap datepicker -->   <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">   <link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="Stylesheet" type="text/css" />     <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>     &

Dependent dropdown using ajax

index.php     <!DOCTYPE html>     <html>     <head>         <title></title>         <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">     </head>     <body>     <div class="container" style="margin-top: 70px;">     <div class="row">     <div class="col-md-3"></div>     <div class="col-md-6">                     <form  action="insert.php" method="post">                     <div class="form-group">     <label for="exampleInputEmail1">Department</label>     <input type="text" name="department" class="form-control" placeholder="Department">   </div>   <div class="form-group">     <label for="exampleInputPassword1">Subject</label>         <input ty

Simple PHP Mysql Shopping Cart

<?php    session_start();   $connect = mysqli_connect("localhost", "root", "root", "test");   if(isset($_POST["add_to_cart"]))   {        if(isset($_SESSION["shopping_cart"]))        {             $item_array_id = array_column($_SESSION["shopping_cart"], "item_id");             if(!in_array($_GET["id"], $item_array_id))             {                  $count = count($_SESSION["shopping_cart"]);                  $item_array = array(                       'item_id'               =>     $_GET["id"],                       'item_name'               =>     $_POST["hidden_name"],                       'item_price'          =>     $_POST["hidden_price"],                       'item_quantity'          =>     $_POST["quantity"]                  );                  $_SESSION["shopping_cart"][$count] = $

Checkbox in select

<!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>Untitled Document</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"     rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script> <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"     rel="stylesheet" type=&

Simple login

<?php $con=mysqli_connect("localhost","root","root","oes2") or die(mysqli_error($con)); if(isset($_POST['submit'])) {     extract($_POST);     $q=mysqli_query($con,"select * from student where stdname='$username' and stdpassword='$password'") or die(mysqli_error($con));     if(mysqli_num_rows($q)==1)         {     $row=mysqli_fetch_array($q);         $_SESSION['uname_admin']=$row['admname'];             echo"<script>";         echo"alert('Login Successfully..');";         echo"window.location.href='dashboard.php'";         echo"</script>";     }     else     {         echo"<script>";         echo"alert('Login Failed..Pls Try again..');";         echo"</script>";     } } ?>

ajax insert

index.php <!DOCTYPE html> <html> <head>   <title>Ajax insert</title>   <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> </head> <body> <div class="container">     <div class="row">           <div class="col-md-3"></div>           <div class="col-md-6">           <form >             <div class="form-group">           

cookie login

<?php $con = mysqli_connect("localhost","root","root","cookielogin") or die(mysqli_error($con)); session_start(); if(isset($_POST['btn_login'])) {     extract($_POST);             $query=mysqli_query($con,"select * from login where  username='$username' and password='$password'" ) or die(mysqli_error($con));      $row=mysqli_fetch_assoc($query);            if($row)      {          if(!empty($_POST['re'])){          setcookie("username",$_POST['username'],time() + (48*60*60));          setcookie("password",$_POST['password'],time() + (24*60*60));          }          else          {              if(isset($_COOKIE['username']))              {                  setcookie("username","");              }              if(isset($_COOKIE['password']))              {                  setcookie("password","");              

change password

<?php           if(isset($_POST['change']))           {               include"include/connection.php";             $query='select * from enabler_register where username="'.$_SESSION['username'].'"and password="'.$_POST['pass'].'"';                $res=mysqli_query($con,$query);             if(mysqli_num_rows($res)>0)             {                 if(strlen($_POST['pass1'])>=6)                 {                     if($_POST['pass1']==$_POST['pass2'])                     {                     $query1='update enabler_register set password="'.$_POST['pass1'].'" ,password="'.$_POST['pass2'].'"                     where username="'.$_SESSION['username'].'"';                     $res1=mysqli_query($con,$query1);                     //echo $query1;                     if($res1)                    

photo upload

<html> <head>  <script src="assets/js/jquery-1.10.2.js"></script>     <!-- BOOTSTRAP SCRIPTS -->     <script src="assets/js/bootstrap.js"></script>     <!-- PAGE LEVEL SCRIPTS -->     <script src="assets/js/bootstrap-fileupload.js"></script>     <!-- METISMENU SCRIPTS -->     <script src="assets/js/jquery.metisMenu.js"></script>     <!-- CUSTOM SCRIPTS -->     <script src="assets/js/custom.js"></script>         </head> <body> <form method="post" enctype="multipart/form-data"> <input  type="file" name="photo"><br> <input type="submit" name="submit" value="SEND"> </form>     <?php         $con=mysqli_connect("localhost","root","root","img") or die(mysqli_error()); if(isset($_POST['submit

view record

<!DOCTYPE html> <html> <head>     <title></title> </head> <body> <?php      $dbname="demo";     $con=mysqli_connect("localhost","root","root","demo") or die(mysqli_error());    $query=mysqli_query($con,"select * from tbl1 ") or die(mysqli_error($con));    ?>    <table border="1">            <tr>                <td>Name</td>                <td>surname</td>            </tr>      <?php      while($row=mysqli_fetch_array($query))      {      extract($row);      ?>      <tr>          <td><?php echo $row['name']; ?></td>          <td><?php echo $row['surname']; ?></td>      </tr> <?php } ?>    </table> </body> </html>

Assignment

Image

How to insert data into Database using PHP

 1. Create Form and give name form.php, the file look like :            <form method="post" action="insert.php">              <label>Name</label>              <input type="text" name="name" />                          <label>Surname</label>              <input type="text" name="surname" />             <input type="submit" name="submit" />          </form>  2. create database connection and give name db.php and create table give name tbl1, the file look like :       <?php             $con=mysqli_connect("localhost","root","root","demo") or     die(mysqli_error()); 3. create insert.php file , the file look like :          <?php          include "db.php"; if(isset($_POST['submit']))     {            extract($_POST);     $query=mysqli_query($con,"insert into tbl1

How to connect to database using PHP and MySQL

<?php $dbname="your db name"; $server="your server name e.g. localhost"; $username="your username e.g. root"; $password=" your password"; $connect = mysqli_connect($dbname,$server,$username,$password) or die(mysqli_error()); if($connect) {  echo "Database connection successfully.."; }else { echo "error while connecting  to the database"; } ?>