ianhaney50 Posted July 26, 2015 Share Posted July 26, 2015 Hi I am trying to alter the flow of my php website, the flow currently is the user pays via PayPal and then redirects back from PayPal to the site to fill out their info but now the client wants users to sign up first and then redirected to PayPal but the data is only stored in the database if payment is successful so am using PayPal IPN, I have turned it on via the PayPal account and set the url of the ipn php code I am getting the page showing but no sign up form, below is my signup form, is it ok if someone can check to see if is ok, I have error reporting in but is showing no errors <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php require_once("functions.php"); require_once("db-const.php"); ?> <?php $title = "Register - The Tax Elephants"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); ?> <!--CONTENT--> <?php if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message ## connect mysql server $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); # check connection if ($mysqli->connect_errno) { echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } ## query database # prepare data for insertion $username = mysqli_real_escape_string($mysqli, $_POST['username']); $password = md5($_POST['password']); /*$password = $_POST['password'];*/ $name = mysqli_real_escape_string($mysqli, $_POST['name']); $email = mysqli_real_escape_string($mysqli, $_POST['email']); $address1 = mysqli_real_escape_string($mysqli, $_POST['address1']); $address2 = mysqli_real_escape_string($mysqli, $_POST['address2']); $town = mysqli_real_escape_string($mysqli, $_POST['town']); $county = mysqli_real_escape_string($mysqli, $_POST['county']); $postcode = mysqli_real_escape_string($mysqli, $_POST['postcode']); $telnumber = mysqli_real_escape_string($mysqli, $_POST['telnumber']); $mobnumber = mysqli_real_escape_string($mysqli, $_POST['mobnumber']); $model = mysqli_real_escape_string($mysqli, $_POST['model']); $numplate = mysqli_real_escape_string($mysqli, $_POST['numplate']); $tax = ($_POST['tax']); $mot = ($_POST['mot']); $insurance = ($_POST['insurance']); $mobnumber = preg_replace('/^07/','447',$mobnumber); $mobnumber = str_replace(' ', '', $mobnumber); # check if username and email exist else insert // u = username, e = emai, ue = both username and email already exists $exists = ""; $result = $mysqli->query("SELECT username from users WHERE username = '{$username}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "u"; } $result = $mysqli->query("SELECT email from users WHERE email = '{$email}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "e"; } if ($exists == "u") echo "<p><b>Error:</b> Username already exists!</p>"; else if ($exists == "e") echo "<p><b>Error:</b> Email already exists!</p>"; else if ($exists == "ue") echo "<p><b>Error:</b> Username and Email already exists!</p>"; /*redirect_to("login.php?msg=Registered successfully");*/ /*redirect_to("http://www.paypal.com");*/ redirect_to ("http://www.sandbox.paypal.com"); } else { /*echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>";*/ exit(); } ?> <div id="column-whole"> <!-- The HTML registration form --> <form action="ipn.php" method="post"> <label>Username:</label> <input type="text" name="username" required="required" placeholder="Please Enter your chosen username"/> <br /> <label>Password:</label> <div class='pwdwidgetdiv' id='thepwddiv'></div> <script type="text/javascript" > var pwdwidget = new PasswordWidget('thepwddiv','password'); pwdwidget.MakePWDWidget(); </script> <noscript> <input type="password" name="password" required="required" placeholder="Please Enter your chosen password"/> </noscript> <br /> <div class='para'> <br /> <label>Name:</label> <input type="text" name="name" required="required" placeholder="Please Enter your name"> <br /> <label>Email:</label> <input type="email" name="email" required="required" placeholder="Please Enter your email"/> <br /> <label>Address Line 1:</label> <input type="text" name="address1" required="required" placeholder="Please Enter the first line of your address"/> <br /> <label>Address Line 2:</label> <input type="text" name="address2" placeholder="Please Enter the second line of your address"/> <br /> <label>Town:</label> <input type="text" name="town" required="required" placeholder="Please Enter your town"/> <br /> <label>County:</label> <input type="text" name="county" required="required" placeholder="Please Enter your county"/> <br /> <label>Postcode:</label> <input type="text" name="postcode" required="required" placeholder="Please Enter your postcode"/> <br /> <label>Telephone Number:</label> <input type="text" name="telnumber" required="required" placeholder="Please Enter your landline number"/> <br /> <div data-tip="please enter as 447123456789 format"> <label>Mobile Number:</label> <input type="text" name="mobnumber" required="required" placeholder="Please Enter your mobile number"/> </div> <label>Car/Van Model:</label> <input type="text" name="model" required="required" placeholder="Please Enter your car/van model"/> <br /> <label>Car/Van Number Plate:</label> <input type="text" name="numplate" required="required" placeholder="Please Enter your car/number plate"/> <br /> <label>Car Tax Renewal Date :</label> <input type="text" id="datepicker" name="tax" placeholder="Please Enter your Car Tax Renewal Date"/> <br> <label>MOT Expiry Date :</label> <input type="text" id="datepicker2" name="mot" placeholder="Please Enter your MOT Expiry Date"/> <br /> <label>Insurance Expiry Date :</label> <input type="text" id="datepicker3" name="insurance" placeholder="Please Enter your Insurance Expiry Date"/> <br><br> <div class="box"> <label>I agree to the <a href="terms.php" target="_blank">terms</a></label> </div> <input type="checkbox" class="checkbox" id="the-terms" value="I Agree"> <!-- Specify a Subscribe button. --> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="ItemName" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemNumber" value="ARSTE0001" /> <input type="hidden" name="ItemDesc" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemPrice" value="3.00" /> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="Y"> <!-- Set recurring payments until canceled. --> <input type="hidden" name="src" value="1"> <!--DO NOT PROMPT FOR SHIPPING ADDRESS--> <input type="hidden" name="no_shipping" value="1"> <input class="dw_button" type="submit" name="submit" value="Regster and Pay (£3.00)" disabled="disabled" id="submitBtn" /> </form> <a class="haveaccount" href="login.php">I already have an account...</a> </form> </div> <!--CONTENT--> <script> $(document).ready(function() { var the_terms = $("#the-terms"); the_terms.click(function() { if ($(this).is(":checked")) { $("#submitBtn").removeAttr("disabled"); } else { $("#submitBtn").attr("disabled", "disabled"); } }); }); </script> <?php include( 'includes/footer.php' ); ?> I am confused as to why? Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/ Share on other sites More sharing options...
QuickOldCar Posted July 26, 2015 Share Posted July 26, 2015 You have 2 closing form tags </form> <a class="haveaccount" href="login.php">I already have an account...</a> </form> Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517432 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 I have a link in another forum http://www.codingforums.com/php/343325-need-help-php-coding-flow.html#post1452910 Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517433 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 Ahh yeah didn't see that I have taken the one out now that is below the <a class="haveaccount" href="login.php">I already have an account...</a> line But the form does not show still? Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517434 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 I have updated the coding slightly as realised I had a closing div tag missing and then took out some other PHP code as I put it in the ipn.php file which will show shortly as just trying to get 1 thing at a time working and get the form showing <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php require_once("functions.php"); require_once("db-const.php"); ?> <?php $title = "Register - The Tax Elephants"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); ?> <!--CONTENT--> <?php if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message ## connect mysql server $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); # check connection if ($mysqli->connect_errno) { echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } # check if username and email exist else insert // u = username, e = emai, ue = both username and email already exists $exists = ""; $result = $mysqli->query("SELECT username from users WHERE username = '{$username}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "u"; } $result = $mysqli->query("SELECT email from users WHERE email = '{$email}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "e"; } if ($exists == "u") echo "<p><b>Error:</b> Username already exists!</p>"; else if ($exists == "e") echo "<p><b>Error:</b> Email already exists!</p>"; else if ($exists == "ue") echo "<p><b>Error:</b> Username and Email already exists!</p>"; /*redirect_to("login.php?msg=Registered successfully");*/ /*redirect_to("http://www.paypal.com");*/ redirect_to("http://www.sandbox.paypal.com"); } /*else { /*echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>"; }*/ exit(); ?> <div id="column-whole"> <!-- The HTML registration form --> <form action="ipn.php" method="post"> <label>Username:</label> <input type="text" name="username" required="required" placeholder="Please Enter your chosen username"/> <br /> <label>Password:</label> <div class='pwdwidgetdiv' id='thepwddiv'></div> <script type="text/javascript" > var pwdwidget = new PasswordWidget('thepwddiv','password'); pwdwidget.MakePWDWidget(); </script> <noscript> <input type="password" name="password" required="required" placeholder="Please Enter your chosen password"/> </noscript> <br /> <div class='para'> <br /> <label>Name:</label> <input type="text" name="name" required="required" placeholder="Please Enter your name"> <br /> <label>Email:</label> <input type="email" name="email" required="required" placeholder="Please Enter your email"/> <br /> <label>Address Line 1:</label> <input type="text" name="address1" required="required" placeholder="Please Enter the first line of your address"/> <br /> <label>Address Line 2:</label> <input type="text" name="address2" placeholder="Please Enter the second line of your address"/> <br /> <label>Town:</label> <input type="text" name="town" required="required" placeholder="Please Enter your town"/> <br /> <label>County:</label> <input type="text" name="county" required="required" placeholder="Please Enter your county"/> <br /> <label>Postcode:</label> <input type="text" name="postcode" required="required" placeholder="Please Enter your postcode"/> <br /> <label>Telephone Number:</label> <input type="text" name="telnumber" required="required" placeholder="Please Enter your landline number"/> <br /> <div data-tip="please enter as 447123456789 format"> <label>Mobile Number:</label> <input type="text" name="mobnumber" required="required" placeholder="Please Enter your mobile number"/> </div> <label>Car/Van Model:</label> <input type="text" name="model" required="required" placeholder="Please Enter your car/van model"/> <br /> <label>Car/Van Number Plate:</label> <input type="text" name="numplate" required="required" placeholder="Please Enter your car/number plate"/> <br /> <label>Car Tax Renewal Date :</label> <input type="text" id="datepicker" name="tax" placeholder="Please Enter your Car Tax Renewal Date"/> <br> <label>MOT Expiry Date :</label> <input type="text" id="datepicker2" name="mot" placeholder="Please Enter your MOT Expiry Date"/> <br /> <label>Insurance Expiry Date :</label> <input type="text" id="datepicker3" name="insurance" placeholder="Please Enter your Insurance Expiry Date"/> <br><br> <div class="box"> <label>I agree to the <a href="terms.php" target="_blank">terms</a></label> </div> <input type="checkbox" class="checkbox" id="the-terms" value="I Agree"> <!-- Specify a Subscribe button. --> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="ItemName" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemNumber" value="ARSTE0001" /> <input type="hidden" name="ItemDesc" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemPrice" value="3.00" /> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="Y"> <!-- Set recurring payments until canceled. --> <input type="hidden" name="src" value="1"> <!--DO NOT PROMPT FOR SHIPPING ADDRESS--> <input type="hidden" name="no_shipping" value="1"> <input class="dw_button" type="submit" name="submit" value="Regster and Pay (£3.00)" disabled="disabled" id="submitBtn" /> </form> <a class="haveaccount" href="login.php">I already have an account...</a> </div> </div> <!--CONTENT--> <script> $(document).ready(function() { var the_terms = $("#the-terms"); the_terms.click(function() { if ($(this).is(":checked")) { $("#submitBtn").removeAttr("disabled"); } else { $("#submitBtn").attr("disabled", "disabled"); } }); }); </script> <?php include( 'includes/footer.php' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517435 Share on other sites More sharing options...
QuickOldCar Posted July 26, 2015 Share Posted July 26, 2015 What does the html source file show? Btw is no need to keep coming in and out of php the way you are. Also where is $error defined? if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further Is your error reporting actually working? Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517437 Share on other sites More sharing options...
mac_gyver Posted July 26, 2015 Share Posted July 26, 2015 your code was exit()'ing inside the else {} statement (which had nothing to do with a mysqli error, it matched your if (isset($_POST['submit']) ... statement) and never reached the <form>. after the change you made, it's still exit()'ing. why do you have that exit(); statement in your code? Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517438 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 I have taken on board the comments and is now working, below is the updated code just to confirm, was the reason nothing was displayed was because of the exit(); is that right? <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); require_once("functions.php"); require_once("db-const.php"); $title = "Register - The Tax Elephants"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message ## connect mysql server $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); # check connection if ($mysqli->connect_errno) { echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } # check if username and email exist else insert // u = username, e = emai, ue = both username and email already exists $exists = ""; $result = $mysqli->query("SELECT username from users WHERE username = '{$username}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "u"; } $result = $mysqli->query("SELECT email from users WHERE email = '{$email}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "e"; } if ($exists == "u") echo "<p><b>Error:</b> Username already exists!</p>"; else if ($exists == "e") echo "<p><b>Error:</b> Email already exists!</p>"; else if ($exists == "ue") echo "<p><b>Error:</b> Username and Email already exists!</p>"; /*redirect_to("login.php?msg=Registered successfully");*/ /*redirect_to("http://www.paypal.com");*/ redirect_to("http://www.sandbox.paypal.com"); } /*else { echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>"; }*/ ?> <div id="column-whole"> <!-- The HTML registration form --> <form action="ipn.php" method="post"> <label>Username:</label> <input type="text" name="username" required="required" placeholder="Please Enter your chosen username"/> <br /> <label>Password:</label> <div class='pwdwidgetdiv' id='thepwddiv'></div> <script type="text/javascript" > var pwdwidget = new PasswordWidget('thepwddiv','password'); pwdwidget.MakePWDWidget(); </script> <noscript> <input type="password" name="password" required="required" placeholder="Please Enter your chosen password"/> </noscript> <br /> <div class='para'> <br /> <label>Name:</label> <input type="text" name="name" required="required" placeholder="Please Enter your name"> <br /> <label>Email:</label> <input type="email" name="email" required="required" placeholder="Please Enter your email"/> <br /> <label>Address Line 1:</label> <input type="text" name="address1" required="required" placeholder="Please Enter the first line of your address"/> <br /> <label>Address Line 2:</label> <input type="text" name="address2" placeholder="Please Enter the second line of your address"/> <br /> <label>Town:</label> <input type="text" name="town" required="required" placeholder="Please Enter your town"/> <br /> <label>County:</label> <input type="text" name="county" required="required" placeholder="Please Enter your county"/> <br /> <label>Postcode:</label> <input type="text" name="postcode" required="required" placeholder="Please Enter your postcode"/> <br /> <label>Telephone Number:</label> <input type="text" name="telnumber" required="required" placeholder="Please Enter your landline number"/> <br /> <div data-tip="please enter as 447123456789 format"> <label>Mobile Number:</label> <input type="text" name="mobnumber" required="required" placeholder="Please Enter your mobile number"/> </div> <label>Car/Van Model:</label> <input type="text" name="model" required="required" placeholder="Please Enter your car/van model"/> <br /> <label>Car/Van Number Plate:</label> <input type="text" name="numplate" required="required" placeholder="Please Enter your car/number plate"/> <br /> <label>Car Tax Renewal Date :</label> <input type="text" id="datepicker" name="tax" placeholder="Please Enter your Car Tax Renewal Date"/> <br> <label>MOT Expiry Date :</label> <input type="text" id="datepicker2" name="mot" placeholder="Please Enter your MOT Expiry Date"/> <br /> <label>Insurance Expiry Date :</label> <input type="text" id="datepicker3" name="insurance" placeholder="Please Enter your Insurance Expiry Date"/> <br><br> <div class="box"> <label>I agree to the <a href="terms.php" target="_blank">terms</a></label> </div> <input type="checkbox" class="checkbox" id="the-terms" value="I Agree"> <!-- Specify a Subscribe button. --> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="ItemName" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemNumber" value="ARSTE0001" /> <input type="hidden" name="ItemDesc" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemPrice" value="3.00" /> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="Y"> <!-- Set recurring payments until canceled. --> <input type="hidden" name="src" value="1"> <!--DO NOT PROMPT FOR SHIPPING ADDRESS--> <input type="hidden" name="no_shipping" value="1"> <input class="dw_button" type="submit" name="submit" value="Regster and Pay (£3.00)" disabled="disabled" id="submitBtn" /> </form> <a class="haveaccount" href="login.php">I already have an account...</a> </div> </div> <!--CONTENT--> <script> $(document).ready(function() { var the_terms = $("#the-terms"); the_terms.click(function() { if ($(this).is(":checked")) { $("#submitBtn").removeAttr("disabled"); } else { $("#submitBtn").attr("disabled", "disabled"); } }); }); </script> <?php include( 'includes/footer.php' ); ?> I will do a test now and hopefully will work with the ipn.php, if not is it ok to post on this thread any errors etc. Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517440 Share on other sites More sharing options...
QuickOldCar Posted July 26, 2015 Share Posted July 26, 2015 Good eye mac_gyver, not even sure how I missed that exit and so obvious. Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517441 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 Just done a test and the error I got on the ipn.php page is below Warning: fgets(): SSL: Connection reset by peer in /home/sites/taxelephants.uk/public_html/ipn.php on line 30 The ipn.php code is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; /*$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);*/ $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $username = mysqli_real_escape_string($mysqli, $_POST['username']); $password = md5($_POST['password']); $name = mysqli_real_escape_string($mysqli, $_POST['name']); $email = mysqli_real_escape_string($mysqli, $_POST['email']); $address1 = mysqli_real_escape_string($mysqli, $_POST['address1']); $address2 = mysqli_real_escape_string($mysqli, $_POST['address2']); $town = mysqli_real_escape_string($mysqli, $_POST['town']); $county = mysqli_real_escape_string($mysqli, $_POST['county']); $postcode = mysqli_real_escape_string($mysqli, $_POST['postcode']); $telnumber = mysqli_real_escape_string($mysqli, $_POST['telnumber']); $mobnumber = mysqli_real_escape_string($mysqli, $_POST['mobnumber']); $model = mysqli_real_escape_string($mysqli, $_POST['model']); $numplate = mysqli_real_escape_string($mysqli, $_POST['numplate']); $tax = ($_POST['tax']); $mot = ($_POST['mot']); $insurance = ($_POST['insurance']); $mobnumber = preg_replace('/^07/','447',$mobnumber); $mobnumber = str_replace(' ', '', $mobnumber); # insert data into mysql database $sql = "INSERT INTO `users` (`id`, `username`, `password`, `name`, `email`, `address1`, `address2`, `town`, `county`, `postcode`, `telnumber`, `mobnumber`, `model`, `numplate`) VALUES (NULL, '{$username}', '{$password}', '{$name}', '{$email}', '{$address1}', '{$address2}', '{$town}', '{$county}', '{$postcode}', '{$telnumber}', '{$mobnumber}', '{$model}', '{$numplate}')"; $result = $mysqli->query($sql); $id = $mysqli->insert_id; $insurance = date('Y-m-d', strtotime($_POST['insurance'])); $mot = date('Y-m-d', strtotime($_POST['mot'])); $tax = date('Y-m-d', strtotime($_POST['tax'])); $sql = "INSERT INTO renewal (id, item_id, renewal_date) VALUES ($id, 1, '$insurance'), ($id, 2, '$mot'), ($id, 3, '$tax')"; if ($mysqli->query($sql)) { $to = $_POST['email']; $subject = "Thank you for your purchase - Login Credentials"; $message = "Thank you for purchasing and signing up, your login information is below \r\n Username: {$_POST['username']} \r\n Password: {$_POST['password']} \r\n You can now login at http://www.taxelephants.uk/login';"; $header = "From:noreply@taxelephants.uk \r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; } } else if (strcmp ($res, "INVALID") == 0) { $to = 'info@taxelephants.co.uk'; $subject = 'Invalid Payment'; $message = ' Dear Administrator, A payment has been made but is flagged as INVALID. Please verify the payment manually and contact the buyer. Buyer Email: '.$email.' '; $headers = 'From:noreply@taxelephants.co.uk' . "\r\n"; mail($to, $subject, $message, $headers); fclose ($fp); } } } } ?> I understand mysql is not good to use and is better to use mysqli but just want to get it working first Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517442 Share on other sites More sharing options...
ianhaney50 Posted July 26, 2015 Author Share Posted July 26, 2015 Think I sort of sussed it, I am not getting any errors now but the page is blank and is not adding nothing to the database nor is it redirecting to PayPal not sure if it is the register.php or the ipn.php causing the issue the ipn.php code is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: www.sanbox.paypal.com\r\n"; $header .= "Accept: */*\r\n"; $header .= "Connection: Close\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "\r\n"; /*$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);*/ $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); $res = stream_get_contents($fp, 2048); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $username = mysqli_real_escape_string($mysqli, $_POST['username']); $password = md5($_POST['password']); $name = mysqli_real_escape_string($mysqli, $_POST['name']); $email = mysqli_real_escape_string($mysqli, $_POST['email']); $address1 = mysqli_real_escape_string($mysqli, $_POST['address1']); $address2 = mysqli_real_escape_string($mysqli, $_POST['address2']); $town = mysqli_real_escape_string($mysqli, $_POST['town']); $county = mysqli_real_escape_string($mysqli, $_POST['county']); $postcode = mysqli_real_escape_string($mysqli, $_POST['postcode']); $telnumber = mysqli_real_escape_string($mysqli, $_POST['telnumber']); $mobnumber = mysqli_real_escape_string($mysqli, $_POST['mobnumber']); $model = mysqli_real_escape_string($mysqli, $_POST['model']); $numplate = mysqli_real_escape_string($mysqli, $_POST['numplate']); $tax = ($_POST['tax']); $mot = ($_POST['mot']); $insurance = ($_POST['insurance']); $mobnumber = preg_replace('/^07/','447',$mobnumber); $mobnumber = str_replace(' ', '', $mobnumber); # insert data into mysql database $sql = "INSERT INTO `users` (`id`, `username`, `password`, `name`, `email`, `address1`, `address2`, `town`, `county`, `postcode`, `telnumber`, `mobnumber`, `model`, `numplate`) VALUES (NULL, '{$username}', '{$password}', '{$name}', '{$email}', '{$address1}', '{$address2}', '{$town}', '{$county}', '{$postcode}', '{$telnumber}', '{$mobnumber}', '{$model}', '{$numplate}')"; $result = $mysqli->query($sql); $id = $mysqli->insert_id; $insurance = date('Y-m-d', strtotime($_POST['insurance'])); $mot = date('Y-m-d', strtotime($_POST['mot'])); $tax = date('Y-m-d', strtotime($_POST['tax'])); $sql = "INSERT INTO renewal (id, item_id, renewal_date) VALUES ($id, 1, '$insurance'), ($id, 2, '$mot'), ($id, 3, '$tax')"; if ($mysqli->query($sql)) { $to = $_POST['email']; $subject = "Thank you for your purchase - Login Credentials"; $message = "Thank you for purchasing and signing up, your login information is below \r\n Username: {$_POST['username']} \r\n Password: {$_POST['password']} \r\n You can now login at http://www.taxelephants.uk/login';"; $header = "From:noreply@taxelephants.uk \r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; } } else if (strcmp ($res, "INVALID") == 0) { $to = 'info@taxelephants.co.uk'; $subject = 'Invalid Payment'; $message = ' Dear Administrator, A payment has been made but is flagged as INVALID. Please verify the payment manually and contact the buyer. Buyer Email: '.$email.' '; $headers = 'From:noreply@taxelephants.co.uk' . "\r\n"; mail($to, $subject, $message, $headers); fclose ($fp); } } } ?> The coding from the register.php file is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); require_once("functions.php"); require_once("db-const.php"); $title = "Register - The Tax Elephants"; $pgDesc=""; $pgKeywords=""; include ( 'includes/header.php' ); if (isset($_POST['submit']) && isset($error) == '') { // if there is no error, then process further echo "<p class='success'>Form has been submitted successfully.</p>"; // showing success message ## connect mysql server $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); # check connection if ($mysqli->connect_errno) { echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } # check if username and email exist else insert // u = username, e = emai, ue = both username and email already exists $exists = ""; $result = $mysqli->query("SELECT username from users WHERE username = '{$username}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "u"; } $result = $mysqli->query("SELECT email from users WHERE email = '{$email}' LIMIT 1"); if ($result->num_rows == 1) { $exists .= "e"; } if ($exists == "u") echo "<p><b>Error:</b> Username already exists!</p>"; else if ($exists == "e") echo "<p><b>Error:</b> Email already exists!</p>"; else if ($exists == "ue") echo "<p><b>Error:</b> Username and Email already exists!</p>"; /*redirect_to("login.php?msg=Registered successfully");*/ /*redirect_to("http://www.paypal.com");*/ redirect_to("http://www.sandbox.paypal.com"); } /*else { echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>"; }*/ ?> <div id="column-whole"> <!-- The HTML registration form --> <form action="ipn.php" method="post"> <label>Username:</label> <input type="text" name="username" required="required" placeholder="Please Enter your chosen username"/> <br /> <label>Password:</label> <div class='pwdwidgetdiv' id='thepwddiv'></div> <script type="text/javascript" > var pwdwidget = new PasswordWidget('thepwddiv','password'); pwdwidget.MakePWDWidget(); </script> <noscript> <input type="password" name="password" required="required" placeholder="Please Enter your chosen password"/> </noscript> <br /> <div class='para'> <br /> <label>Name:</label> <input type="text" name="name" required="required" placeholder="Please Enter your name"> <br /> <label>Email:</label> <input type="email" name="email" required="required" placeholder="Please Enter your email"/> <br /> <label>Address Line 1:</label> <input type="text" name="address1" required="required" placeholder="Please Enter the first line of your address"/> <br /> <label>Address Line 2:</label> <input type="text" name="address2" placeholder="Please Enter the second line of your address"/> <br /> <label>Town:</label> <input type="text" name="town" required="required" placeholder="Please Enter your town"/> <br /> <label>County:</label> <input type="text" name="county" required="required" placeholder="Please Enter your county"/> <br /> <label>Postcode:</label> <input type="text" name="postcode" required="required" placeholder="Please Enter your postcode"/> <br /> <label>Telephone Number:</label> <input type="text" name="telnumber" required="required" placeholder="Please Enter your landline number"/> <br /> <div data-tip="please enter as 447123456789 format"> <label>Mobile Number:</label> <input type="text" name="mobnumber" required="required" placeholder="Please Enter your mobile number"/> </div> <label>Car/Van Model:</label> <input type="text" name="model" required="required" placeholder="Please Enter your car/van model"/> <br /> <label>Car/Van Number Plate:</label> <input type="text" name="numplate" required="required" placeholder="Please Enter your car/number plate"/> <br /> <label>Car Tax Renewal Date :</label> <input type="text" id="datepicker" name="tax" placeholder="Please Enter your Car Tax Renewal Date"/> <br> <label>MOT Expiry Date :</label> <input type="text" id="datepicker2" name="mot" placeholder="Please Enter your MOT Expiry Date"/> <br /> <label>Insurance Expiry Date :</label> <input type="text" id="datepicker3" name="insurance" placeholder="Please Enter your Insurance Expiry Date"/> <br><br> <div class="box"> <label>I agree to the <a href="terms.php" target="_blank">terms</a></label> </div> <input type="checkbox" class="checkbox" id="the-terms" value="I Agree"> <!-- Specify a Subscribe button. --> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="ItemName" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemNumber" value="ARSTE0001" /> <input type="hidden" name="ItemDesc" value="Automatic Reminder Service - Tax Elephants" /> <input type="hidden" name="ItemPrice" value="3.00" /> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="Y"> <!-- Set recurring payments until canceled. --> <input type="hidden" name="src" value="1"> <!--DO NOT PROMPT FOR SHIPPING ADDRESS--> <input type="hidden" name="no_shipping" value="1"> <input class="dw_button" type="submit" name="submit" value="Regster and Pay (£3.00)" disabled="disabled" id="submitBtn" /> </form> <a class="haveaccount" href="login.php">I already have an account...</a> </div> </div> <!--CONTENT--> <script> $(document).ready(function() { var the_terms = $("#the-terms"); the_terms.click(function() { if ($(this).is(":checked")) { $("#submitBtn").removeAttr("disabled"); } else { $("#submitBtn").attr("disabled", "disabled"); } }); }); </script> <?php include( 'includes/footer.php' ); ?> I thought it might be the register.php as the redirect code is in there but maybe it needs moving to the ipn.php or the ipn.php coding might need altering or moving Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517447 Share on other sites More sharing options...
maxxd Posted July 27, 2015 Share Posted July 27, 2015 Your ipn.php code is connecting and selecting the DB using mysql_, but using mysqli_ for the interaction. Change the connection and selection calls. Quote Link to comment https://forums.phpfreaks.com/topic/297481-need-help-with-php-coding-and-flow/#findComment-1517473 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.