Delete Record In php With alert message

Head part alert message –

<head>

function ConfirmDelete()
{
var x = confirm(“Are you sure you want to delete?”);
if (x)
return true;
else
return false;
}

</head>

Body Part Php + Html code –

<form name=”myform” action=”delete.php” method=”post”>
<table border=”0″ width=”80%”cellspacing=”2″ cellpadding=”2″ align=”center”>
<tr>
<td colspan=”3″ align=”right” style=”font-size:24px” height=”50px;”> <b>Delete Customer Bill Details</b>
</td>
</tr>
<tr>
<td>&nbsp;
</td>
</tr>
<?php
if(isset($_GET[‘id’]))
{
$id =$_GET[‘id’];
$query = “select * from billdetails where billno = ‘”.$id.”‘”;
$qu1 = mysql_query($query, $con);
while($res= mysql_fetch_array($qu1))
{
$billno = $res[“billno”];
$bdate = $res[“bdate”];
$pname = $res[“pname”];
$venue = $res[“venue”];
$mobile = $res[“mobile”];
$email = $res[“email”];
$servicedes = $res[“servicedes”];
$samount = $res[“samount”];
$ramount = $res[“ramount”];
$famount = $res[“famount”];
$otherser = $res[“otherser”];
$oamount = $res[“oamount”];
$rswords = $res[“rswords”];
$tamount = $res[“tamount”];
$servicetax = $res[“servicetax”];
$discount = $res[“discount”];
$gamount = $res[“gamount”];
}
}
?>
<tr>
<td align=”left” style=”font-size:16px”><b>Bill No.:</b><span class=”star”>*</span>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”billno” value=”<?php echo $billno; ?>” required />
</td>
<td align=”left” style=”font-size:16px”><b>Bill Date:</b><span class=”star”>*</span>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” id=”datepicker3″ name=”billdate” value=”<?php echo $bdate; ?>” required  />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Party Name:</b><span class=”star”>*</span>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”pname” value=”<?php echo $pname; ?>” required  />
</td>
<td align=”left” style=”font-size:16px”><b>Venue:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”venue” value=”<?php echo  $venue; ?>”  />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Mobile No.:</b><span class=”star”>*</span>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”mobileno” value=”<?php echo $mobile; ?>” required />
</td>
<td align=”left” style=”font-size:16px”><b>Email Id:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”email” value=”<?php echo $email; ?>”  />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Service Descriptions:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”sd” value=”<?php echo $servicedes; ?>”   style=”width:234px; height:61px;”/>
</td>
<td align=”left” style=”font-size:16px”><b>Amount:</b><span class=”star”>*</span>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”samount” value=”<?php echo $samount; ?>” required />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Room Rent Amount: </b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”ramount” value=”<?php echo $ramount; ?>”  />
</td>
<td align=”left” style=”font-size:16px”><b>Food Beverage Amount:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”famount” value=”<?php echo $famount; ?>”  />
</td>
</tr>

<tr>
<td align=”left” style=”font-size:16px”><b>Other Services:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”os” value=”<?php echo $otherser; ?>”  />
</td>
<td align=”left” style=”font-size:16px”><b>Amount:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”oamount” value=”<?php echo $oamount; ?>”  />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px” rowspan=”4″><b> Rs. In words:<b>
</td>
<td align=”left” style=”font-size:16px” rowspan=”4″><input type=”text” name=”words” value=”<?php echo $rswords; ?>”   style=”width:234px; height:75px;” />    </td>
<td align=”left” style=”font-size:16px”><b>Total Amount:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”tamount”value=”<?php echo $tamount; ?>”  />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Service Tax:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”stax” value=”<?php echo $servicetax; ?>”  required />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Discount:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”discount” value=”<?php echo $discount; ?>” />
</td>
</tr>
<tr>
<td align=”left” style=”font-size:16px”><b>Grand Total:</b>
</td>
<td align=”left” style=”font-size:16px”><input type=”text” name=”gt” value=”<?php echo $gamount; ?>”  />
</td>

</tr>
<?php
if(isset($_POST[‘Delete’]))
{
if(x == true)
{
$cid = $_POST[‘billno’];
$Query = “delete from billdetails where billno ='”.$cid.”‘”;
$up = mysql_query($Query,$con);
if($up)
{?>

<?php
}
}
else
{ ?>

<?php }
}
?>
<tr>
<td align=”left” style=”font-size:16px” >
</td>
<td align=”left” style=”font-size:16px” colspan=”3″ height=”45px;”> <input type=”submit” name=”Delete” Onclick=”return ConfirmDelete();” value=”Delete”  /></td>
</tr>

</table>
</form>

PayPal standard payment gateway integration in PHP

 

PayPal has two environments such as Sandbox and Real Time. Sandbox environment help developers to do their test transaction before the project go live. Real Time environment is used after project live.

Creating a new Sandbox test account:

At first we need to create a new Sandbox test account. Following steps would be help to create Sandbox account.

  • Step 1 – Go to the https://developer.paypal.com/. Log in with your PayPal account. If you don’t have any PayPal account, first sign up at PayPal. Once the sign up is completed, login with this account.
  • Step 2 – After logged in you would be redirected to the developer home page. Now click on the “Dashboard” link from the top navigation menu.
  • Step 3 – Click on the “Accounts” link under the “Sandbox” label from the left menu section.
  • Step 4 – Create buyer account and merchant account from the “Create Account” link. For buyer account you need to select “Personal” radio button under the “Account type” section or select Business radio button for merchant account.

Database Tables Creation:

We have created two tables named products and payments. products data is stored into the products table and payments table is used for storing the transaction information provided by PayPal.

CREATE TABLE `products` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `price` float(10,2) NOT NULL,
 `status` tinyint(1) NOT NULL DEFAULT '1',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `payments` (
 `payment_id` int(11) NOT NULL AUTO_INCREMENT,
 `item_number` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `txn_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `payment_gross` float(10,2) NOT NULL,
 `currency_code` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
 `payment_status` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 PRIMARY KEY (`payment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

We have used four files for complete the PayPal payment process.

db_config.php File:

Database configuration and connection is done here.

<?php
//Database credentials
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'codexworld';
//Connect with the database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

if ($db->connect_errno) {
    printf("Connect failed: %s\n", $db->connect_error);
    exit();
}
?>

products.php File:

In this file all products would be displayed from the MySQL database with PayPal Buy Now button. Follow the comment(<!–– ––>) tags to know about the form hidden fields.

<?php

include 'db_config.php';

//Set useful variables for paypal form
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
$paypal_id = 'info@codexworld.com'; //Business Email

//fetch products from the database
$results = $db->query("SELECT * FROM products");

while($row = $results->fetch_assoc())
{
?>

    	<img src="images/<?php echo $row['image']; ?>"/>
    	Name: <?php echo $row['name']; ?>
    	Price: <?php echo $row['price']; ?>
    	<form action="<?php echo $paypal_url; ?>" method="post">

        <!-- Identify your business so that you can collect the payments. -->
        <input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
        
        <!-- Specify a Buy Now button. -->
        <input type="hidden" name="cmd" value="_xclick">
        
        <!-- Specify details about the item that buyers will purchase. -->
        <input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
        <input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
        <input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
        <input type="hidden" name="currency_code" value="USD">
        
        <!-- Specify URLs -->
        <input type='hidden' name='cancel_return' value='http://example.com/cancel.php'>
        <input type='hidden' name='return' value='http://example.com/success.php'>
        
        <!-- Display the payment button. -->
        <input type="image" name="submit" border="0"
        src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
        <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
    
    </form>

<?php } ?>

success.php File:

Once the PayPal payment is successful, buyer would be redirected to this page. We have received the transaction information with $_GET variable and insert transaction data into the database. If the payment is successful, then buyer would be see the success message otherwise failed message.

<?php
include 'db_config.php';

//Store transaction information from PayPal
$item_number = $_GET['item_number']; 
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];

//Get product price
$productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
$productRow = $productResult->fetch_assoc();
$productPrice = $productRow['price'];

if(!empty($txn_id) && $payment_gross == $productPrice){
    //Insert tansaction data into the database
    $insert = $db->query("INSERT INTO payments(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
    $last_insert_id = $db->insert_id;
?>

<h1>Your payment has been successful.</h1>
<h1>Your Payment ID - <?php echo $last_insert_id; ?>.</h1>

<?php
}else{
?>

<h1>Your payment has failed.</h1>

<?php
}
?>

cancel.php File:

If the buyers wish to cancel payment at the PayPal payment page, then buyer would be redirected to this page.

<h1>Your PayPal transaction has been canceled.</h1>

When your application payment flow testing is completed, you need to change $paypal_url variable value with https://www.paypal.com/cgi-bin/webscr and change $paypal_id variable value with the original PayPal Business ID.

Create contact form and send mail in PHP

simple Contact us form create by HTML

<form action="test.php"method="post">
<table width="400"border="0"cellspacing="2"cellpadding="0">
<tr>
<td width="29%"class="bodytext">Your name:</td>
<td width="71%"><input name="name"type="text"id="name"size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email"type="text"id="email"size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment"cols="45"rows="6"id="comment"class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left"valign="top"><input type="submit"name="Submit"value="Send"></td>
</tr>
</table>
</form>
Send mail by php code –
<?php
$ToEmail = 'youremail@site.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>