Php/mysql register form with paypal.

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 10
Joined: Thu Mar 28, 2013 11:18 pm

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" "">
<html xmlns="">  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<link rel="stylesheet" type="text/css" href="style1.css" />
<script type="text/javascript" src=""></script>
<script src=""></script>
<script type="text/javascript" src="placeholder.js"></script>

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>";
     	$registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')");
        	echo "<h1>Success</h1>";
        	echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
     		echo "<h1>Error</h1>";
        	echo "<p>Sorry, your registration failed. Please go back and try again.</p>";    
<form method="post" action="" 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" />



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

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

require_once ('includes/config.php');

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

// PayPal settings
$paypal_email = '';

$return_url = '';
$cancel_url = '';
$notify_url = '';

	// 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)."&";

	//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


Post Reply