Php code

--------------------------ajax wala page code----------------------------------

<?php
if(isset($_GET["maincat"]))
            {     
              $conn=mysqli_connect("localhost","root","","giftshop");
              $cat=$_GET["maincat"];
              $select="select * from sub_category where cat_id=$cat";
              $result=mysqli_query($conn,$select)or die(mysqli_error($conn));
              while($a1=mysqli_fetch_array($result))
              {
               print "<option value='$a1[0]'>$a1[2]</option>";
               }
            }

?>

------------------------------------------------end of ajax code--------------------------

 

---------------------ajax script code for send select option value to ajax page------------

 
<script type="text/javascript">
function showsubcat(a)
{
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  obj=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  obj=new ActiveXObject("Microsoft.XMLHTTP");
  }
   
obj.onreadystatechange=function()
  {
  if (obj.readyState==4 && obj.status==200)
    {
    document.getElementById("subcat").innerHTML=obj.responseText;
    }
  }
   
obj.open("GET","ajax.php?maincat="+a,true);
obj.send();
}
</script>

----------------end of ajax script code----------------------------------------------------------


-----------------------------login pge code---------------------

<?php
session_start();   // session start work//
if(isset($_POST["login"]))
{
  $email=$_POST["email"];
  $password=$_POST["password"];
  $conn=mysqli_connect("localhost","root","","giftshop");
  $select="select * from customer where email='$email' and password='$password'";
  $running=mysqli_query($conn,$select) or die(mysqli_error($conn));
  $count=mysqli_affected_rows($conn);
  $userdata=mysqli_fetch_array($running);
  if($count==0)
  {
    print "<script>alert('user name and password is wrong ? Try Again');</script>";
  }
  else
  {    
      if($userdata['usertype']=="admin")
      {
        $_SESSION["admin"]=$userdata['name'];
        $_SESSION["adminemail"]=$uerdata['email'];
        header("location:index.php");
      }
    else
        {
        $_SESSION["username"]=$userdata['name'];
        $_SESSION["useremail"]=$userdata['email'];
        header("location:shopnow.php");
        }
}
}    
?>

--------------------end of login page code----------------


---------------logout page code----------------------------------

<?php
session_start();
session_regenerate_id();
session_unset();

print "<script>
alert('user logout successfully');
</script>";
?>

<script>
document.location="login.php";
</script>

--------------end of logout page code-------------------------

----------all product code show and buy now send query code-------------

 <?php
               $conn=mysqli_connect("localhost","root","","giftshop");
               $select="select * from product";
               $result=mysqli_query($conn,$select) or die(mysqli_error($conn));
               while($show=mysqli_fetch_array($result))
               {
                print "<div class='productshow'>
                <img src='product/$show[image]'>
                <b>Name: $show[product_name]<b>
                <b>Price: $show[product_price]</b>
                <a id='addtocart' href='buynow.php?pid=$show[pid]&&qty=1'>ADD TO CART</a>
                </div>";
               }
               ?>

-------------end of all product code----------query end-----------------------


--------product add to cart and qty automatic update code--------------

 <?php
session_start();
if(isset($_SESSION["username"]))
{
  $sid=session_id();
  $username=$_SESSION["username"];
  $useremail=$_SESSION["useremail"];
}
      if(isset($_GET["pid"]))
      {
        $pid=$_GET["pid"];
        $qty=$_GET["qty"];
        $conn=mysqli_connect("localhost","root","","giftshop");
        $select="select * from product where pid=$pid";
        $result=mysqli_query($conn,$select) or die(mysqli_error($conn));
        $data=mysqli_fetch_array($result);

        //$qty=$_GET["qty"];
        $total=$qty*$data['product_price'];
        $conn2=mysqli_connect("localhost","root","","giftshop");
        $select="select * from cart where user_id='$sid' and pid=$pid";
        $run=mysqli_query($conn2,$select) or die(mysqli_error($conn2));
        $rowcount=mysqli_fetch_array($run);
        if($rowcount)
        {
        //print "<script>alert('product allready added')</script>";
       $qty2=$qty+$rowcount['qty'];
       $total2=$qty2*$rowcount['price'];
       $conn=mysqli_connect("localhost","root","","giftshop");
       $updatecart="update cart set qty=$qty2, total='$total2' where user_id='$sid' and
       pid=$pid";
       $run=mysqli_query($conn,$updatecart) or die(mysqli_error($conn));
       if($run==true)
                {
                 header("location:viewcart2.php?sid=$sid");
                }
       }
        else
          {   
              $conn=mysqli_connect("localhost","root","","giftshop");
              $insert="insert into cart(user_id,user_name,user_email,product,pid,qty,price,photo,total)
               values('$sid','$username','$useremail','$data[product_name]',$pid,$qty,$data[product_price],'$data[image]',$total)";
               $added=mysqli_query($conn,$insert) or die(mysqli_error($conn));
               if($added==true)
                {
                 header("location:viewcart2.php?sid=$sid");
                }
    }
   }                    
?>

-----------end of product add to cart and qty update automatic code--------


------multi product qty update 1 click -----------------

<?php
/* Check if button name "update" is active, do this */


if(isset($_POST['update']))
{
 
  $count=count($_POST["id"]);

for($i=0;$i<$count;$i++)
{
  $net_price = $_POST['qty'][$i] * $_POST['price'][$i];

  $sql1="UPDATE cart SET qty='" . $_POST['qty'][$i] . "', total='" . $net_price . "' WHERE id='" . $_POST['id'][$i] . "'";

$result1=mysqli_query($conn,$sql1);
}

print "<script>alert('product cart update');</script>";
print "<script>document.location:viewcart.php?sid=$sid</script>";
}
?> 

html code---

 <?php
if(isset($_GET["sid"]))
{
$sid=$_GET["sid"];
$conn=mysqli_connect("localhost","root","","giftshop");
$sql="SELECT * FROM cart where user_id='$sid'";
$result=mysqli_query($conn,$sql) or die(mysqli_error($conn));
$c=0;
while($a=mysqli_fetch_array($result))
{
  $c+=$a['total'];
?>

  <form method="POST">
    <input type="hidden" name="id[]" value="<?php print "$a[id]"; ?>">
    <input type="hidden" name="price[]" value="<?php print "$a[price]"; ?>">
    <ul><li><?php print "<img src='product/$a[photo]'>"; ?></li>
            <li><?php print "$a[product]"; ?></li>
            <li><?php print "$a[price]"; ?></li>
            <li><input type="number" name="qty[]" value="<?php print "$a[qty]"; ?>"></li>
             <li><?php print "$a[total]"; ?></li>
             <li><?php print "<a href='deletecart.php?sid=$sid && pid=$a[pid]'>DELETE</a>"; ?></li>
          </ul>
<?php } } ?>


---------end of multi product qty update code------

 

 

----------any thing delete code----------------------------

<?php
    $orderid=$_GET["oid"];
    $conn=mysqli_connect("localhost","root","","giftshop");
    $delete="delete from orders where order_id=$orderid";
    $run=mysqli_query($conn,$delete) or die(mysqli_error($conn));
    if($run==true)
    {

        header("location:vieworder.php");
    }
?>

---------end of delete data code---------------------------- 

 

-----------anything update code------------------------------------

<?php
               $userid=$_GET["userid"];
               $conn=mysqli_connect("localhost","root","","giftshop");
               $select="select * from customer where user_id=$userid";
               $result=mysqli_query($conn,$select) or die(mysqli_error($conn));
               $show=mysqli_fetch_array($result);
{

           if(isset($_POST["update"]))
         {
              $name=$_POST["name"];
              $phone=$_POST["phone"];
              $city=$_POST["city"];
              $conn=mysqli_connect("localhost","root","","giftshop");
              $update="update customer set phone=$phone, city='$city' where user_id=$userid";
              $run=mysqli_query($conn,$update) or die(mysqli_error($conn));
              if($run==true)
              {
                print "<script>
                alert('user data update sucessfully');
                 </script>";

                print "<script>
                document.location='customer.php';         
                 </script>";
              }
          }
}
?>

-------------end of update code-------------------------------------


----------insert anything in databse--------------------------

$conn=mysqli_connect("localhost","root","","giftshop");
  $insert="insert into product(product_name,product_unit,product_status,cat_id,sub_id,product_price,

product_content,product_description,image,variation)
  values('$name','$unit','$status',$maincat,
  $subcat,'$price','$content','$description','$image','$variation')";
  $added=mysqli_query($conn,$insert) or die(mysqli_error($conn));
  move_uploaded_file($_FILES["image"]["tmp_name"],'product/'.$_FILES["image"]["name"]);

    if($added==true)
    {
     print "<script>
     alert('New product added sucessfully');
     </script>";
    }

-------end of insert code--------------------------------------


----------CLEART SHOPPING CART CODE-----------

<?php
if(isset($_GET["sid"]) && ($_GET["pid"]))
{
    $sid=$_GET["sid"];
    $pid=$_GET["pid"];
    $conn=mysqli_connect("localhost","root","","giftshop");
    $delete="delete from cart where user_id='$sid' and pid=$pid";
    $run=mysqli_query($conn,$delete) or die(mysqli_error($conn));
    if($run==true)
    {

        header("location:viewcart.php?sid=$sid");
    }
 }
?>
 

-------END OF ALL ITEM DELETE CODE-----------





No comments

Thanks for comment with us

Powered by Blogger.