Search This Blog

27 July 2018

PHP using Shopping Cart

PHP Using Shopping Cart


Index.php:

  <!DOCTYPE html>
<html>
<head>
<style>
.overlay {
  background: #304352;
  opacity: 0.4;
  position: absolute;
 right: 0;
}
.overlay1 {
  background: #fff;
  opacity: 0.4;
  position: absolute;

  top: 0;
  left: 0;
  right: 0;

}
</style>
<title> Admin Panel </title>
</head>
<script src="js/jquery.js"> </script>
<link rel="stylesheet" type="text/css" href=" css/bootstrap.min.css">
<body>
<div class="container">
<div class="row">
<center> <h1> Shopping Cart </h1> </center>
<div class="col-md-12">
<ul type="none">
<?php $con=mysqli_connect("localhost","root","","test");
   $sql=" select * from product ";
   $res=$con->query($sql);
   while($row= mysqli_fetch_array($res)){
?>
<li >
<div class="col-md-3" >
<img width="100%" src="images/<?php echo $row['image']; ?>" >
<center>
<h4> <?php echo $row['pname']; ?> </h4>
<h4> <?php echo $row['pdesc']; ?> </h4>
<h4> <?php echo "$".$row['price']; ?> </h4>
<a href="index.php?id=<?php echo $row['id']; ?>" class="btn btn-danger"> Add cart </a>
</center>
</div>
</li><?php } ?>
</ul><br>
<h4><a href="show.php" target="_blank">Show cart</a></h4>
</div>
</div>
</div>
</body>
</html>
<?php
session_start();

if(empty($_SESSION['cart']))
$_SESSION['cart']=array();
if(isset($_GET['id'])){
array_push($_SESSION['cart'],@$_GET['id']);
}
?>

Show Product:
<?php
$con=mysqli_connect("localhost","root","","test");

if(!isset($_SESSION['cart']) or $_SESSION['cart']==NULL)
echo " No product";
else{
$id=implode(',',$_SESSION['cart']);
$sql=" select * from product where id in($id) ";
$res=$con->query($sql);
echo "<table class='table table-hover'><tr>
<th> Id </th> <th> name </th> <th> Description </th><th> Image </th> <th> Quantity </th> <th> price </th>
</tr>";
$price=0;
while($row=mysqli_fetch_array($res)){
$price+=$row['price']*$row['quantity'];
echo "

<tr>
<td> ".$row['id']." </td>
<td> ".$row['pname']." </td>
<td> ".$row['pdesc']." </td>
<td> <img  width='18%' src='images/".$row['image']."' </td>
<td> <input style='width:50px;' value='".$row['quantity']."' type='text' onkeyup='inc(".$row['id'].")' name='qty[]' id='qty".$row['id']."'></td>
<td id='s".$row['id']."'>".$row['price']*$row['quantity']." </td>
<td> <a href='?rm=".$row['id']."'> Remove </a> </td>
</tr>
";



}echo " <tr>
<td colspan='5'>
Total
</td>
<td> ".$price." </td>
</tr>

</table> <br>";

echo " <h4> <a href='?all'> remove all </a> </h4>";

}

Remove Product :


<?php     //Remove All
session_start();
if(isset($_GET['all'])){
unset($_SESSION['cart']);
}


else if (isset($_GET['rm'])){  //Remove Particular cart
foreach ($_SESSION['cart'] as $key => $pro) {
if($pro==$_GET['rm']){
unset($_SESSION['cart'][$key]);
}

}
}
?>

Increase Quantity:

<script type="text/javascript">
function inc(e){
var qty=document.getElementById('qty'+e).value;
$.post("inc.php",{id:e,qty:qty},function(data){
document.getElementById('s'+e).innerHTML=data;
});
}

</script>


<?php
session_start();
$con=mysqli_connect("localhost","root","","test");
if(isset($_POST['id'])){
$id=$_POST['id'];
$qty=$_POST['qty'];
$sql=" update product set quantity='$qty' where id='$id' ";
$con->query($sql);
$sql=" select * from product where id='$id' ";
$res=$con->query($sql);
while($row=mysqli_fetch_array($res)){
$price=$row['quantity']*$row['price'];
echo $_SESSION['price']=$price;
}
}

?>

# 3 Files 

1.index.php
2.show.php
3.inc.php


Output:
















26 July 2018

Javascript Validation

JavaScript Form Validation

<!DOCTYPE html>
<html>
<head>
<title>Javascript Validation</title>
</head>
<style type="text/css">
.inpt {
    padding: 10px;
    width: 290px;
    border-radius: 4px;
    border: 1px solid #a59c9c;
    font-size: 16px;
    box-sizing: content-box;
}
input[type="button"] {
    padding: 8px;
    width: 8%;
    border-radius: 4px;
    border: 1px solid #c5bfbf;
    margin-left: 4%;
}
</style>
<script type="text/javascript">
var frm=document.getElementById('frm');
var sub=document.getElementById('sub');

 function empty(e){
        user = document.getElementById("unm").value;
    pwd = document.getElementById("pass").value;
 
    if(user=="" && pwd==""){
        alert('username and password is Empty');
      event.preventDefault();
     
    }else{
     
    }
}
function ckdate(){
    var dt=document.getElementById('dt').value;
    var today = new Date();
    var y = today.getFullYear();                     
    var m = ("0" + (today.getMonth() + 1)).slice(-2);
    var dy = ("0" + today.getDate()).slice(-2); 
    var cur=y+"-"+m+"-"+dy;
     if(cur < dt){
       alert('NOT select Future date');
       event.preventDefault();
       document.getElementById('dt').value='';
    }else{
       
    }
}



function val(e){
var fname=document.getElementById('fname').value;
var lname=document.getElementById('lname').value;
var email=document.getElementById('email').value;
var pwd=document.getElementById('pwd').value;
var cpwd=document.getElementById('cpwd').value;
var pno=document.getElementById('pno').value;





if(fname==""){
document.getElementById('e1').innerHTML="Enter Your First Name";
document.getElementById('e1').style.color="red";
}else{
document.getElementById('e1').innerHTML="";
}
if (lname=="") {document.getElementById('e2').innerHTML="Enter Your Last Name";
document.getElementById('e2').style.color="red";}
else{
document.getElementById('e2').innerHTML="";
}
if(email==""){document.getElementById('e3').innerHTML="Enter Your Email";
document.getElementById('e3').style.color="red";}
else{
document.getElementById('e3').innerHTML="";
}
if(pwd==""){document.getElementById('e4').innerHTML="Enter Your Password";
document.getElementById('e4').style.color="red";}
else{
document.getElementById('e4').innerHTML="";
}
if(cpwd==""){document.getElementById('e5').innerHTML="Enter Your Confirm Password";
document.getElementById('e5').style.color="red";}
else{
document.getElementById('e5').innerHTML="";
}
if(pno==""){document.getElementById('e6').innerHTML="Enter Your phone Number";
document.getElementById('e6').style.color="red";}
else{
document.getElementById('e6').innerHTML="";
}

}

function fnm(){
var fname=document.getElementById('fname').value;
if(fname.length > 10){
document.getElementById('e1').innerHTML="The Character is less then 10";
document.getElementById('e1').style.color="red";
}else{
document.getElementById('e1').innerHTML="";
}
}
function lnm(){
var lname=document.getElementById('lname').value;
if(lname.length > 10){
document.getElementById('e2').innerHTML="The Character is less then 10";
document.getElementById('e2').style.color="red";
}else{
document.getElementById('e2').innerHTML="";
}
}

function passwd(){
var pwd=document.getElementById('pwd').value;
if(pwd.length < 8){
document.getElementById('e4').innerHTML="Password is greater then 8";
document.getElementById('e4').style.color="red";
}else{
document.getElementById('e4').innerHTML="";
}
}
function cnfrm(){
var pwd=document.getElementById('pwd').value;
var cpwd=document.getElementById('cpwd').value;
if(pwd==cpwd){
 document.getElementById('e5').innerHTML="";
}else{
     document.getElementById('e5').innerHTML="Password is NOT Mached";
document.getElementById('e5').style.color="red";
//document.getElementById('cpwd').value='';
document.getElementById('cpwd').focus();
}
}

function phone(){
var pno=document.getElementById('pno').value;
if(pno.length > 10){
document.getElementById('e6').innerHTML="Phone Number is max 10";
document.getElementById('e6').style.color="red";
}else{
document.getElementById('e6').innerHTML="";
}
}


</script>
<body>
<center><h1>Javascript Form Validation</h1></center>
<center>
<form id="frm" >
<table>
<tr><td>First Name</td>
<td><input class="inpt" onkeyup="fnm()"  placeholder="Enter First name" type="text" id="fname"></td>
<td><span id="e1"></span></td></tr>
<tr><td>Last Name</td>
<td><input class="inpt" onkeyup="lnm()" placeholder="Enter Last name" type="text" id="lname"></td>
<td><span id="e2"></span></td</tr>
<tr><td>Email</td>
<td><input class="inpt" placeholder="Enter Email" type="text" id="email"></td>
<td><span id="e3"></span></td</tr>
<tr><td>Password</td>
<td><input class="inpt" onkeyup="passwd()" placeholder="Enter Password" type="password" id="pwd"></td>
<td><span id="e4"></span></td</tr>
<tr><td>Confirm Password</td>
<td><input class="inpt" onchange="cnfrm()" placeholder="Enter Confirm Passowrd" type="password" id="cpwd"></td>
<td><span id="e5"></span></td</tr>
<tr><td>Phone Number</td>
<td><input class="inpt" onkeyup="phone()" placeholder="Enter Phone Number" type="text" id="pno"></td>
<td><span id="e6"></span></td</tr>
</table><br>
<input type="button" id="sub" onclick="val(event)"  value="check">
</form>
</center>

</body>
</html>






05 May 2018

SIMPLE SEARCH ENGINE


SIMPLE SEARCH ENGINE



<?php header("Cache-Control: no-cache, must-revalidate"); ?>
<html>
<head></head>
<style>
.seo {
    width: 40%;
    height: 4%;
    border-radius: 4px;
}
.sub {
    height: 5%;
    width: 12%;
    border-radius: 6px;
    background-color: #4683ea;
    color: white;
}
.clear-margin {
    margin: 0;
  }
  .space-top {
    margin-top: 10px;
  }
  .space-right {
    margin-right: 10px;
  }
  .icon-left {
    margin-right: 5px;
  }
  .icon-right {
    margin-left: 5px;
  }
  .labels {
    word-spacing: 5px;
    line-height: 2;
  }
  .label-keyword {
    display: inline-block;
    background: #7eb0db;
    color: white;
    font-size: 0.9em;
    padding: 5px;
    border: 1px solid #357ebd;
  }
  .link-disguise {
    color: inherit;
  }
  .link-disguise:hover {
    color: inherit;
  }
  @media (max-width: 992px) {
    .clear-margin-sm {
      margin-bottom: 0;
    }
  }
  body {
    font-family: 'Lato', "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: #f0f0f0;
    color: #333333;
    font-size: 16px;
  }
  .text-bolder {
    font-weight: bold;
  }
  @media only screen {
    .container {
      max-width: 50em;
    }
  }
  @media (max-width: 480px) {
    ul {
      padding-left: 25px;
    }
    /*
          .mobile-title {
              display: inline-block;
              margin-left: 5px;
              font-weight: bold;
              text-transform: uppercase;
              vertical-align: middle;
          }
  */
    .background-details {
      display: block;
    }
    .background-details .icon {
      max-width: inherit;
      min-width: inherit;
      text-align: left;
    }
    .background-details .icon,
    .background-details .info {
      display: block;
      padding: 10px 0;
    }
    .background-details .title {
      display: none;
    }
    .card-nested {
      padding: 5px 0;
    }
  }
  .profile-card {
    display: table;
    width: 100%;
  }
  .profile-pic {
    display: table-cell;
    vertical-align: top;
    padding: 1rem 4rem 0 0 ;
  }
  .profile-pic img {
    width: 100px;
    height: 100px;
  }
  .contact-details {
    display: table-cell;
  }
  .contact-details .detail {
    display: inline-flex;
    line-height: 2;
    margin-right: -1rem;
  }
  .contact-details .detail .icon {
    padding-right: 7px;
    color: #888;
  }
  .contact-details .detail .info {
    font-size: 0.8em;
  }
  .social-links {
    line-height: 2.5;
  }
  .social-link {
    display: block;
  }
  .social-link span {
    display: inline-block;
    vertical-align: middle;
  }
  .social-link:hover,
  .social-link:focus {
    text-decoration: none;
  }
  .social-link .fa {
    text-align: center;
    width: 2em;
  }
  .fa-github {
    color: #454545;
  }
  .fa-github:hover,
  .fa-github:focus {
    text-decoration: none;
    color: #2b2b2b;
  }
  .fa-twitter {
    color: #33ccff;
  }
  .fa-twitter:hover,
  .fa-twitter:focus {
    text-decoration: none;
    color: #00bfff;
  }
  .fa-rss {
    color: #f36f24;
  }
  .fa-rss:hover,
  .fa-rss:focus {
    text-decoration: none;
    color: #d8560c;
  }
  .fa-linkedin {
    color: #007bb6;
  }
  .fa-linkedin:hover,
  .fa-linkedin:focus {
    text-decoration: none;
    color: #005983;
  }
  .fa-skype {
    color: #12a5f4;
  }
  .fa-skype:hover,
  .fa-skype:focus {
    text-decoration: none;
    color: #0986ca;
  }
  .fa-stack-overflow {
    color: #8e8e92;
  }
  .fa-stack-overflow:hover,
  .fa-stack-overflow:focus {
    text-decoration: none;
    color: #747479;
  }
  .fa-soundcloud {
    color: #e8822d;
  }
  .fa-soundcloud:hover,
  .fa-soundcloud:focus {
    text-decoration: none;
    color: #cc6916;
  }
  .fa-pinterest {
    color: #bd091f;
  }
  .fa-pinterest:hover,
  .fa-pinterest:focus {
    text-decoration: none;
    color: #8c0717;
  }
  .fa-vimeo {
    color: #17b3e8;
  }
  .fa-vimeo:hover,
  .fa-vimeo:focus {
    text-decoration: none;
    color: #128fba;
  }
  .fa-behance {
    color: #2c98cf;
  }
  .fa-behance:hover,
  .fa-behance:focus {
    text-decoration: none;
    color: #2379a5;
  }
  .fa-codepen {
    color: #1c1c1c;
  }
  .fa-codepen:hover,
  .fa-codepen:focus {
    text-decoration: none;
    color: #020202;
  }
  

</style>
<body>
<center>
<form method="post" action="" >
<input class="seo" type="text" name="s1"  autocomplete="off"  ><br>
<input class="sub" type="submit" name="s" value="search" ><br>

<a href="https://accounts.google.com/signin">SIGN IN</a>
</form>
</center>
</body>
</html>

<?php
clearstatcache();
header("Cache-Control: no-cache, must-revalidate");
session_start();
if(isset($_POST['s'])){
$url=$_POST['s1'];
$_SESSION['url']=$url;
$_SESSION['gle']="http://www.bing.com/search?q=".$_SESSION['url'];

}
?>

<?php
error_reporting(0);
 echo '<iframe width="1250"  height="1200" src="'.$_SESSION['gle'].'" ></iframe>';
 ?>


OUTPUT:










24 April 2018

PHP Mail Using Localhost

                            PHP Mail Using Localhost 


Switch Your Xampp or Wamp Dir go to Your htdocs Directory and then 
Switch Your PHP directory 

Open Your Configuration Files open php.ini file notepad or Other Editor 

Search mail_functions  

Add the Some Configuration and 

[mail function]

SMTP=localhost

smtp_port=25

sendmail_path = Your send mail .exe
sendmail_path = C:\xampp\sendmail\sendmail.exe

then Save 

Open Your Send Mail Directory and open sendmail configuration 

smtp_server=domain.host.com
smtp_server=smtp.gmail.com

smtp_port=25
smtp_port=587


smtp_ssl=sll ---->Change tls
smtp_ssl=tls   


auth_username=yourgmail.com
auth_password=your gmail password

Then Save and Restart Your Apache Server 

<?php
mail("test@gmail.com","Subject","Body","headers");
?>

Important
From Mail is Changed Option is Less Secure App off 
<html>
<head> </head>
<style> 
   footer{
        position:absolute;
        width:100%;
        bottom:0px;
    }
    img#im{
    height: 110px;
    width: 100%;
    opacity: .4;
}
label#l {
    position: relative;
    top: 70px;
    color: aliceblue;
    font-size: 26px;
    left: 10%;
}
 @media only screen and (max-width : 1000px) {
.stellarnav > ul > li > a { padding: 20px 23px; }

}
li {
    list-style-type: none;
}
#im{
    height:31px;
}
.txt{
    color: #fff;
    margin-left: 2%;
    font-weight: bold;
    font-size: 25px;
    line-height: 23px;
    letter-spacing: -1px;

}
.t{

    font-size: 4vw;
}
.cl{
background-color: #a2d5ac;
}
.inpt{
    width: 100%;
    box-sizing: border-box;
    background-color: #88b991;
    font-size: 18px;
    line-height: 20px;
    padding: 18px 24px;
    display: inline-block;
    vertical-align: top;
    margin: 0 0 8px;
    font-family: grad,serif;
    color: #fff;
    letter-spacing: 1px;
    border: none;
}
::placeholder{
color: white;
opacity: 1;
font-style: italic;
}
#anc:focus{
    background-color:#bce2c3

}
 input[type=radio]{
            display: none;
        }
        .lb{
            color:#4a4949;
            background-color:#bfe4c6;
            padding: 6px 16px;
            cursor: pointer;
            border-radius:3px;
        }
        input[type=radio]:checked +.lb{
            background-color: #88b991;
            color: white;
        }
        .inpt{
    width: 100%;
    box-sizing: border-box;
    background-color: #88b991;
    font-size: 18px;
    line-height: 20px;
    padding: 18px 24px;
    display: inline-block;
    vertical-align: top;
    margin: 0 0 8px;
    font-family: grad,serif;
    color: #fff;
    letter-spacing: 1px;
    border: 1px solid #00000021;
    outline-color:#88b991;
        margin: 0% 0% 3% 0%;
}
::placeholder{
font-style: italic;
color: #ffffff;

}

</style>
<tabel>
<form method="post" action="">
<tr>
<td> mail </td> <td> <input type="email" name="mail" placeholder=" enter mail " </td>
</tr>
<tr>
<td> subject </td> <td> <input type="text" name="subject" placeholder=" enter sunject " </td>
</tr>
<tr>
<td> body </td> <td> <input type="text" name="body" placeholder=" enter body " </td>
</tr>
<input type="submit"  value="send" name="sub">
</form>
</tabel>
<?php  
if(isset($_POST['sub'])){
$mail=$_POST['mail'];
$sub=$_POST['subject'];
$bdy=$_POST['body'];

mail($mail,"$sub,$body,"From: headet");

}


?>


Output :
              

         











Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...