Friday 28 September 2012

Google Search Textbox in Your Website


<font face="Verdana", font size=2, font color="000000">

<FORM method=GET action="http://www.google.com/search">

<input type=hidden name=ie value=UTF-8>

<input type=hidden name=oe value=UTF-8>

<TABLE bgcolor="#FFFFFF"><tr><td>

<A HREF="http://www.google.com/">

<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" border="0" ALT="Google"></A>

</td>

<td>

<INPUT TYPE=text name=q size=31 maxlength=255 value="">

<INPUT type=submit name=btnG VALUE="Google Search">

<font size=-1>

<input type=hidden name=domains value="iWebUnlimited.com"><br>

<input type=radio name=sitesearch value="">
The Web <input type=radio name=sitesearch value="http://www.iwebunlimited.com" checked> iWebUnlimited.com <br>

</font>

</td></tr></TABLE>

</FORM>



demo of Google Search Textbox in Your Website

Tuesday 25 September 2012

Login and Logout Script Using Php and Mysql






login.php

<?php session_start(); ?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");
if(isset($_POST['submit'])&&($_POST['txtuser']!=""))
{
$sql="select * from login where username='".$_POST['txtuser']."' and password='".$_POST['txtpass']."'";
$nsql=mysql_query($sql);
$nofrow=mysql_num_rows($nsql);
if($nofrow>=1)
{
   
    $_SESSION['user']=$_POST['txtuser'];
    ?>
    <script language="javascript">
    window.location="index.php";
    </script>
    <?php

}

if($nofrow<=0)
{
    $_SESSION['user']="";
    echo "Please enter Valid Username and Password";
   

}

}

?>
<form method="post">
<table align="center" border="1">
<tr>

    <td>UserName</td>
    <td><input type="text" name="txtuser" /></td>
</tr>
<tr>
    <td>Password</td>
    <td><input type="password" name="txtpass" /></td>
</tr>
<tr>
    <td><input type="submit" name="submit" value="Submit" /></td>
    <td><input type="reset" name="reset" value="Cancle" />
</tr>

</table>
</form>
</body>
</html>










index.php

<?php session_start(); ?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<a href="logout.php">Logout</a>
<br />

<?php
if($_SESSION['user']=="")
{

    ?>
    <script language="javascript">
    window.location="login.php";
    </script>
    <?php

}
if(isset($_SESSION['user']))
{

    echo "Welcome to ".$_SESSION['user'];
}
else
{

    header("Location:login.php");
}

?>


</body>
</html>










logout.php

<?php session_start();

if(isset($_SESSION['user']))
{
    unset($_SESSION['user']);
    $_SESSION['user']="";
    ?>
    <script language="javascript">
    window.location="login.php";
    </script>
   
    <?php
   

}


?>










Wednesday 19 September 2012

Shopping to Cart Using Mysql Php






product.php

<?php session_start(); ?>
<html>
<head>
</head>
<body>
<?php
echo $_SESSION['username'];
$con=mysql_connect("localhost","root","");
mysql_select_db("test");
$sql="select * from product_item";
$nsql=mysql_query($sql);
?>
<table border="1">
<tr>
    <th>id</th>
    <th>name</th>
    <th>price</th>
    <th>img</th>
    <th>qty</th>
</tr>


<?php
while($row=mysql_fetch_array($nsql))
{
?>
<tr>
    <td><?php echo $row['p_id']; ?></td>
    <td><?php echo $row['p_name']; ?></td>
   
    <td><?php echo $row['p_price']; ?></td>
    <td><?php echo $row['p_img']; ?></td>
    <td><?php echo $row['p_qty']; ?></td>
    <td><?php $pid=$row['p_id'];
        echo "<a href='addtocart.php?id=$pid'>add to cart</a>"; ?></td>


</tr>
   
<?php
}
?>

</table>

</body>
</html>






addtocart.php

<?php
session_start();
$con=mysql_connect("localhost","root","");
mysql_select_db("test");

$ssql="select * from cart_detail where p_id=".$_GET['id']."";
$snrow=mysql_query($ssql);
$nrow=mysql_num_rows($snrow);
if($nrow>=1)
{
    $qsql=mysql_fetch_array($snrow);
    $qty=$qsql['qty']+1;
    echo $usql="update cart_detail set qty='$qty' where p_id=".$_GET['id']." and user_id='".$_SESSION['user']."'";
    mysql_query($usql);
}
if($nrow<=0)
{
    echo $acsql="insert into cart_detail(p_id,qty,user_id) values(".$_GET['id'].",'1','".$_SESSION['user']."')";
    mysql_query($acsql);

}


?>
<script language="JavaScript">
window.location="cart.php";

</script>

cart.php

<?php session_start(); ?>
<html>
<head>
</head>

<body>
<form method="post">
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");

if(isset($_GET['did']))
{
    mysql_query("delete from cart_detail where cart_id=".$_GET['did']." and  user_id='".$_SESSION['user']."'");
}

?>


<table border="1" align="center">
<tr>
    <td>Remove</td>
    <td>Id</td>
    <td>Product Name</td>
    <td>Price</td>
    <td>Quantity</td>
    <td>Total</td>
</tr>
<?php


$acsql="select * from cart_detail where user_id='".$_SESSION['user']."'";
$acnrow=mysql_query($acsql);
$tot=0;
$pname="";
while($acrow=mysql_fetch_array($acnrow))
{


    if(isset($_POST['upsubmit']))
    {
  
    $pid=$acrow['p_id'];
  
    echo $_POST[$pid];
    $qsql="update cart_detail set qty=".$_POST[$pid]." where p_id=$pid and user_id='".$_SESSION['user']."'";
    mysql_query($qsql);
    ?>
    <script language="JavaScript">
    window.location="cart.php";
    </script>
    <?php
    }



    $psql="select * from product_item where p_id=".$acrow['p_id']."";
    $pnrow=mysql_query($psql);
    $prow=mysql_fetch_array($pnrow);
  
  
  
  
?>
    <tr>
        <td><a href="cart.php?did=<?php echo $acrow['cart_id']; ?>">Delete</a></td>
        <td><?php echo $prow['p_id'];  ?></td>
        <td><?php echo $prow['p_name'];  ?>
        <?php
        $pname.=$prow['p_name'];
        ?>
        </td>
        <td><?php echo $prow['p_price'];  ?></td>
        <td><input type="text" name="<?php echo $prow['p_id']; ?>" value="<?php echo $acrow['qty'];  ?>" size="2"></td>
        <td><?php echo $prow['p_price']*$acrow['qty']; ?></td>
        <?php $tot=$tot+$prow['p_price']*$acrow['qty']; ?>
      
    </tr>

<?php

}
?>
<tr>
    <td colspan="6" align="right"><?php echo "Total Amount==".$tot; ?></td>
</tr>
<tr>
    <td colspan="6" align="center"><input type="submit" name="upsubmit" value="Update"></td>
  
</tr>
<tr>
    <td><a href="product.php">Back To Shopping</a></td>
</tr>
</table>

</form>
<form id="paypal_form" action="Payment.php" class="paypal" method="post">

    <input name="cmd" type="hidden" value="_xclick" />

    <input name="no_note" type="hidden" value="3" />


    <input type='hidden' name='currency_code' value='USD'>

   <input type="hidden" name="business" value="dadmom_1349350651_biz@ymail.com">

    <input name="currency_code" type="hidden" value="GBP" />

   <input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />


  
    <input type="hidden" name="item_name" value="<?php echo $pname;  ?>" />
    <input type="hidden" name="amount" value="<?php  echo $tot;  ?>" />

    
   
    <table border="0" align="center">
    <tr>
    <td>
    <input type="hidden" name="return" value="http://localhost/index.php">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
        <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
        </td>
    </tr>
</table>
</form>


</body>
</html>




payment.php

<?php
session_start();



// PayPal settings
$paypal_email = 'dadmom_1349350651_biz@ymail.com';
$return_url = 'http://localhost/paypal_/thanks.php';
$cancel_url = 'http://localhost/paypal_/index.php';
$notify_url = 'http://localhost/paypal_/index.php';

//$item_name = 'Test Item';
//$item_amount = $_SESSION['tot'];

// Include Functions
//include("functions.php");

//Database Connection


// Check if paypal request or response
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){

    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&";

    // Append amount& currency (£) to quersytring so it cannot be edited in html

    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

    //loop for posted values and append to querystring
    foreach($_POST as $key => $value){
        $value = urlencode(stripslashes($value));
        $querystring .= "$key=$value&";
    }

    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);

    // Append querystring with custom field
    //$querystring .= "&custom=".USERID;

    // Redirect to paypal IPN
    header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
    exit();

}else{
    // Response from PayPal
}
?>

thanks.php

<?php
session_start();

$con=mysql_connect("localhost","root","");
mysql_select_db("test");

if(isset($_SESSION['uname']))
{
$asql="select * from cart_detail where user_id='".$_SESSION['uname']."'";

$anrow=mysql_query($asql);
while($arow=mysql_fetch_array($anrow))
{
    $dt=date("d-m-y");
    $psql="select * from product_item where p_id=".$arow['p_id']."";
    $pnrow=mysql_query($psql);
    $prow=mysql_fetch_array($pnrow);
    echo $osql="insert into order_detail(user_id,prd_id,qty,price,status,ord_date)
    values('".$_SESSION['uname']."',".$arow['p_id'].",".$arow['qty'].",".$prow['p_price'].",'padding','$dt')";
    mysql_query($osql);
    mysql_query("delete from cart_detail where user_id='".$_SESSION['uname']."'");
}
}
?>
<h2>Thank You For Shopping.....<?php echo $_SESSION['uname']; ?></h2>
    </div>
        </div>
      </div>


Database:

cart_detail









product_detail












order_detail