jamesxg1 Posted April 25, 2009 Share Posted April 25, 2009 Paypal.php <?php session_start(); ini_set('display_errors', 1); error_reporting(E_ALL); include 'Database/PaypalConfig.php'; include 'CoreFiles/Objects/Class.Database.php'; include 'CoreFiles/Objects/Class.Buyer.php'; include 'Database/Connection.php'; include 'Database/Utility.php'; include 'Database/Settings.php'; $this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if (sizeof($_POST) > 0 && $_GET['confirm'] == 'true') { $buyer = new Buyer(); $keys = array_keys($_POST); foreach ($keys as $key => $value) { $buyer->{$value} = (isset($_POST[$value]) ? $_POST[$value] : ''); } if ($buyer->username == '' || $buyer->email == '' || $buyer->firstname == '' || $buyer->lastname == '' || $buyer->password == '' || $buyer->confirmpassword == '' || $buyer->age == '' || $buyer->address == '' || $buyer->postcode == '') { $_SESSION['status'] = 'validationError'; } else { $buyer->SaveNew(); $_SESSION['status'] = 'confirmed'; } } else { $buyer = new Buyer(); } function get_code($seed_length= { $seed = "234567892345678923456789"; $str = ''; srand((double)microtime()*1000000); for ($i=0;$i<$seed_length;$i++) { $str .= substr ($seed, rand() % 48, 1); } return $str; } $unique = false; do { $cap_code = get_code(); $query = "SELECT `userid` FROM `members` WHERE userid = '$cap_code'" or die(mysql_error()); $sql = mysql_query($query); if(mysql_num_rows($sql) == 0) { $unique = true; } } while(!$unique); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title><?php print $companytitle ?> - Register</title> <link href="CoreFiles/css/style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="main_con"> <div class="content_col1"> <span class="h1"> <?php if (isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed') { echo "Confirm purchase"; } else if (isset($_SESSION['status']) && $_SESSION['status'] == 'validationError') { echo "Please fill all required fields"; } else { echo "Membership Is £20 Per Year."; } ?> <div align="center"> <div align="center"> <form action="<?=isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed'?'https://www.sandbox.paypal.com/cgi-bin/webscr':'./Paypal.php?confirm=true';?>" method="POST"> <h3>Registration Form</h3> <p><b>Username</b><br> <input type="text" name="username" size="20" maxlength="255" class="drop" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->username.'" disabled':''?>> </p> <p><b>Email</b><br> <input name="email" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->email.'" disabled':''?>/> </p> <p><b>First Name</b><br> <input name="firstname" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->firstname.'" disabled':''?>/> </p> <p><b>Last Name</b><br> <input name="lastname" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->lastname.'" disabled':''?>/> </p> <p><b>Password</b><br> <input type="password" name="password" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->password.'" disabled':''?>/> </p> <p><b>Confirm Password</b><br> <input type="password" name="confirmpassword" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->confirmpassword.'" disabled':''?>/> </p> <p> <b>Age:</b> <select size="1" name="age" id="age" class="drop" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'disabled':''?>> <option value="16">16</option> <option value="16">17</option> <option value="16">18</option> <option value="16">19</option> <option value="16">20</option> <option value="16">21</option> <option value="16">22</option> <option value="16">23</option> <option value="16">24</option> <option value="16">25</option> <option value="16">26</option> <option value="16">27</option> <option value="16">28</option> <option value="16">29</option> <option value="16">30</option> <option value="16">31</option> <option value="16">32</option> <option value="16">33</option> <option value="16">34</option> <option value="16">35</option> <option value="16">36</option> <option value="16">37</option> <option value="16">38</option> <option value="16">38</option> <option value="16">39</option> <option value="16">40</option> <option value="16">41</option> <option value="16">42</option> <option value="16">43</option> <option value="16">44</option> <option value="16">45</option> <option value="16">46</option> <option value="16">47</option> <option value="16">48</option> <option value="16">49</option> <option value="16">50</option> <option value="16">51</option> <option value="16">52</option> <option value="16">53</option> <option value="16">54</option> <option value="16">55</option> <option value="16">56</option> <option value="16">57</option> <option value="16">58</option> <option value="16">59</option> <option value="16">60</option> <option value="16">61</option> <option value="16">62</option> <option value="16">63</option> <option value="16">64</option> <option value="16">65</option> <option value="16">66</option> <option value="16">67</option> <option value="16">68</option> <option value="16">69</option> <option value="16">70</option> <option value="16">71</option> <option value="16">72</option> <option value="16">73</option> <option value="16">74</option> <option value="16">75</option> <option value="16">76</option> <option value="16">77</option> <option value="16">78</option> <option value="16">79</option> <option value="16">80</option> <option value="16">81</option> <option value="16">82</option> <option value="16">83</option> <option value="16">84</option> <option value="16">85</option> <option value="16">86</option> <option value="16">87</option> <option value="16">88</option> <option value="16">89</option> <option value="16">90</option> <option value="16">91</option> <option value="16">92</option> <option value="16">93</option> <option value="16">94</option> <option value="16">95</option> <option value="16">96</option> <option value="16">97</option> <option value="16">98</option> <option value="16">99</option> <option value="16">100</option> <option value="16">101</option> <option value="16">102</option> <option value="16">103</option> <option value="16">104</option> <option value="16">105</option> <option value="16">106</option> <option value="16">107</option> <option value="16">108</option> <option value="16">109</option> <option value="16">110</option> <option value="16">111</option> <option value="16">112</option> <option value="16">113</option> <option value="16">114</option> <option value="16">115</option> <option value="16">116</option> <option value="16">117</option> <option value="16">118</option> <option value="16">119</option> <option value="16">120</option> <option value="16">121</option> <option value="16">122</option> <option value="16">123</option> <option value="16">124</option> <option value="16">125</option> </select> </p> <p> <b>Address:</b><br><textarea rows="5" cols="40" name="address" id="$address" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->address.'" disabled':''?>/></textarea> </p> <p> <b>Postcode:</b><br><input type="text" name="postcode" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="'.$buyer->postcode.'" disabled':''?>/> </p> <p> <input type="hidden" name="userid" size="20" maxlength="255" class="input_txt" <?=(isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed')?'value="get_code()'.$buyer->userid.'" disabled':''?>> </p> <div class="submit_con" style="padding:0 0 0 5px"> <?php if (isset($_SESSION['status']) && $_SESSION['status'] == 'confirmed') { //show paypal button ?> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="softwarespin@hotmail.co.uk"> <input type="hidden" name="item_name" value="Membership Subscription"> <input type="hidden" name="item_number" value="MSFF1"> <input type="hidden" name="amount" value="20"> <input type="hidden" name="a3" value="20"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="Y"> <input type="hidden" name="src" value="1"> <input type="hidden" name="src1" value="1"> <input type="hidden" name="return" value="$this_script?action=ipn"> <input type="hidden" name="cancel_return" value="$this_script?action=cancel"> <input type="hidden" id="custom" name="custom" value="<?php print($buyer->buyerId); ?>"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="first_name" value="<?php print($buyer->firstName);?>"> <input type="hidden" name="last_name" value="<?php print($buyer->lastName);?>"> <input type="hidden" name="address1" value="<?php print($buyer->address1);?>"> <input type="hidden" name="city" value="<?php print($buyer->city);?>"> <input type="hidden" name="country" value="<?php print($buyer->country);?>"> <input type="hidden" name="email" value="<?php print($buyer->email);?>"> <input type="hidden" name="notify_url" value="$this_script?action=success"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc.gif" border="0" name="submit" alt="Pay securely via Paypal"></input> <?php } else { ?> <p align="center"> <input name="submit" type="submit" value="Confirm"/> </p> <br> Back to <a href="Login.php" >Login Page</a> <?php } $_SESSION['status'] = null; ?> </div> </form> <br /> <br /> <br /> </div> </body> </html> PaypalConfig.php <?php if (!isset($_SESSION)) { session_start(); } global $configuration; //Database related settings $configuration['db'] = 'family'; //database name $configuration['host'] = 'localhost'; //database host $configuration['user'] = 'root'; //database user $configuration['pass'] = ''; //database password ?> IPN.php <?php include("../PaypalConfig.php"); include("../CoreFiles/Objects/Class.Database.php"); include("../CoreFiles/Objects/Class.Buyer.php"); // 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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30); // get the buyer id that this IPN refers to $custom = $_POST['custom']; if (!$fp) { // HTTP ERROR echo "error"; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment $buyer = new Buyer(); $buyer->Get($custom); $buyer->Paid = 1; $buyer->Save(); } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } } fclose ($fp); } ?> Class.Buyer.php <?php class Buyer { var $id; var $username; var $email; var $firstname; var $lastname; var $password; var $confirmpassword; var $age; var $address; var $postcode; var $userid; var $level = 'P'; var $loggedin = 'Y'; var $pog_attribute_type = array( "id" => array("NUMERIC", "INT", "11"), "username" => array("TEXT", "VARCHAR", "14"), "password" => array("TEXT", "VARCHAR", "35"), "userid" => array("NUMERIC", "INT", "6"), "level" => array("TEXT", "VARCHAR", "1"), "firstname" => array("TEXT", "VARCHAR", "55"), "lastname" => array("TEXT", "VARCHAR", "55"), "age" => array("TEXT", "VARCHAR", "3"), "address" => array("TEXT"), "postcode" => array("TEXT", "VARCHAR", "9"), "email" => array("TEXT", "VARCHAR", "100"), "loggedin" => array("TEXT", "VARCHAR", "1"), ); var $reg_query; function id($id) { $Database = new DatabaseConnection(); $id = 1; $this->id_query = "SELECT * FROM `members` WHERE id = '$id'"; $Database->Query($this->id_query); if ($Database->Rows() > 0) { $id = $id + 1; $this->id_query = "SELECT * FROM `members` WHERE id = '$id'"; $Database->Query($this->id_query); } return $id; } function Save() { $Database = new DatabaseConnection(); $this->reg_query = "INSERT INTO `members` (`id`,`username`,`password`,`userid`,`level`,`firstname`,`lastname`,`age`,`address`,`postcode`,`email`) VALUES( '".$Database->Escape($this->id)."', '".$Database->Escape($this->username)."', '".$Database->Escape($this->password)."', '".$Database->Escape($this->userid)."', '".$Database->Escape($this->level)."', '".$Database->Escape($this->firstname)."', '".$Database->Escape($this->lastname)."', '".$Database->Escape($this->age)."', '".$Database->Escape($this->address)."', '".$Database->Escape($this->postcode)."', '".$Database->Escape($this->email)."', '".$Database->Escape($this->loggedin)."' )"; $Database->Query($this->reg_query); } function SaveNew() { $this->password = ''; return $this->Save(); } } ?> Class.Database.php <?php Class DatabaseConnection { var $connection; var $databaseName; var $result; // ------------------------------------------------------------- function DatabaseConnection() { $this->databaseName = $GLOBALS['configuration']['db']; $serverName = $GLOBALS['configuration']['host']; $databaseUser = $GLOBALS['configuration']['user']; $databasePassword = $GLOBALS['configuration']['pass']; $this->connection = mysql_connect ($serverName, $databaseUser, $databasePassword) or die ('I cannot connect to the database.'); mysql_select_db ($this->databaseName); } // ------------------------------------------------------------- function Close() { mysql_close($this->connection); } // ------------------------------------------------------------- function GetConnection() { return $this->connection; } // ------------------------------------------------------------- function Query($query) { $this->result = mysql_query($query,$this->connection); if (!$this->result) { return('Invalid query: '.mysql_error()); } return $this->result; } function Rows() { if ($this->result != false) { return mysql_num_rows($this->result); } return null; } function AffectedRows() { return mysql_affected_rows(); } function Result($row,$name) { if ($this->Rows() > 0) { return mysql_result($this->result,$row,$name); } return null; } function InsertOrUpdate($query) { $this->result = mysql_query($query,$this->connection); return ($this->AffectedRows() > 0); } function Escape($text) { if (!is_numeric($text)) { return $text; } return $text; } // ------------------------------------------------------------- function Unescape($text) { if (!is_numeric($text)) { return $text; } return $text; } // ------------------------------------------------------------- function GetCurrentId() { return intval(mysql_insert_id($this->connection)); } } ?> Hiya, this whole thing works except the insert into the database part (in class.buyer.php) it was but now its not for some reason and i dont know how to do error triggering in classes :S Cheers, James. Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/ Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 Dude, nobody wants to read through all that crap. Learn basic troubleshooting and learn how to ask questions. Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/#findComment-819095 Share on other sites More sharing options...
jamesxg1 Posted April 25, 2009 Author Share Posted April 25, 2009 Dude, nobody wants to read through all that crap. Learn basic troubleshooting and learn how to ask questions. mate thats a bit harsh dont you think, its the whols script the only thing that needs to be read is the Class.Buyer.php and ok do you have any suggestions on a php advanced class tutorial ? Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/#findComment-819098 Share on other sites More sharing options...
Daniel0 Posted April 25, 2009 Share Posted April 25, 2009 mate thats a bit harsh dont you think Perhaps, but we're not here to do your job for you. If you can't even be bothered taking your time to only post the relevant stuff, then why would someone else use their valuable time on helping you? its the whols script the only thing that needs to be read is the Class.Buyer.php Well, then why are you posting the entire thing? do you have any suggestions on a php advanced class tutorial ? Search the forum for suggestions on OOP/app design books. Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/#findComment-819100 Share on other sites More sharing options...
mrMarcus Posted April 25, 2009 Share Posted April 25, 2009 what exactly is that Escape() function doing? have you echo'd out your query going into the DB? Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/#findComment-819120 Share on other sites More sharing options...
premiso Posted April 25, 2009 Share Posted April 25, 2009 what exactly is that Escape() function doing? have you echo'd out your query going into the DB? Absolutely nothing. Funny. function Escape($text) { if (!is_numeric($text)) { return $text; } return $text; } Can you see anything special happening there? > Quote Link to comment https://forums.phpfreaks.com/topic/155624-mysql-help/#findComment-819123 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.