Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Php/mysql register form with paypal.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Php/mysql register form with paypal.

Postby faces » Wed May 15, 2013 6:15 am

Can someone help me and build me simple paypal ipn script.
Its easy.
I have mysql/php register form and when click submit then open paypal pay now page.

Now i need only that script... If paymet sucess then resdict to another page. If not then open new page where is pay button.
One thing to... need update database too. Add there one row like "Payment Success" or smtf
Easy but hard to me :)

Code: Select all
<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title></title>
<link rel="stylesheet" type="text/css" href="style1.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://www.modernizr.com/downloads/modernizr-latest.js"></script>
<script type="text/javascript" src="placeholder.js"></script>
</head> 
<body> 

<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
   $username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    $email = mysql_real_escape_string($_POST['email']);
   
    $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
     
     if(mysql_num_rows($checkusername) == 1)
     {
        echo "<h1>Error</h1>";
        echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
     }
     else
     {
        $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
        if($registerquery)
        {
           echo "<h1>Success</h1>";
           echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
        }
        else
        {
           echo "<h1>Error</h1>";
           echo "<p>Sorry, your registration failed. Please go back and try again.</p>";   
        }       
     }
}
else
{
   ?>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" name="registerform" id="registerform" target="_top">
      <label for="username">Username:</label><input type="text" name="username" id="username" class="placeholder" placeholder="Username"/><br />
      <label for="password">Password:</label><input type="password" name="password" id="password" class="placeholder" placeholder="Password"/><br />
        <label for="email">Email Address:</label><input type="email" name="email" id="email" class="placeholder" placeholder="Email"/><br />
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="">
      <input type="submit" name="register" id="register" value="Register" />
   </form>
   

</form>
   
   
   <?php
}
?>

</body>
</html>
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm

Re: Php/mysql register form with paypal.

Postby daveismyname » Wed May 15, 2013 10:47 pm

OK that's the problem the form is submitted directly to paypal so you don't have the opportunity to save anything to a database first what you want to to is submit the form to a php page save the data then post to paypal

change the form action to a new php file here's a sample one to collect data, process it and post to paypal
Code: Select all
<?php
require_once ('includes/config.php');

header('Content-Type: text/html; charset=utf-8');

// PayPal settings
$paypal_email = 'info@domain.co.uk';

$return_url = 'http://domain.co.uk/order-complete';
$cancel_url = 'http://domain.co.uk/order-cancelled';
$notify_url = 'http://www.domain.co.uk/paypal/payments.php';

   // Firstly Append paypal account to querystring
   $querystring = "?business=".urlencode($paypal_email)."&";
   $querystring .= "cmd=".urlencode('_cart')."&";
   $querystring .= "upload=".urlencode('1')."&";

   //do form processing
 
   $i = 1;
   foreach($_POST['cart'] as $product_id => $quantity) {            

      $sql = sprintf("SELECT * FROM products WHERE productID = %d;",$product_id);                 
      $result = mysql_query($sql);
      if(mysql_num_rows($result) > 0) {
         $querystring .= "item_name_$i=".urlencode($r->productTitle)."&";
         $querystring .= "item_number_$i=".urlencode($r->productID)."&";
         $querystring .= "amount_$i=".urlencode($r->productValue)."&";
      }         
   $i++;}

   //append the urls
   $querystring .= "return=".urlencode(stripslashes($return_url))."&";
   $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
   $querystring .= "notify_url=".urlencode($notify_url);

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

?>
User avatar
daveismyname
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Oct 15, 2011 3:21 am
Location: Hull, East Yorkshire, England


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.