peter_anderson Posted June 24, 2009 Share Posted June 24, 2009 Hi, I'm creating a script to sell online tickets, but I'm stuck at the order form. Here is what I have so far. <?php //load DB and CONFIG require_once("./config.php"); //load theme $html = file_get_contents("./theme.html"); //start classes $db = new db(); //replace valued variables on tpl //note: you MUST use this if you wish to use PHP on your template!!!!!! $html = str_replace('{sitename}', $sitename, $html); $html = str_replace('{copyright}', $copyright, $html); //get event ID $id = $_GET["event"]; //connect to DB //attempt it $sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']); //check for ERR if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // $query = 'SELECT * from `tickets` WHERE id = ' . $id . ''; $query = $sql->real_escape_string($query); // Perform Query $result = $sql->query($query); $row = $result->fetch_assoc(); //main body $content = '<p><strong>ORDER NOW</strong></p> <p>Thank you for choosing this event.</p> <p>Please use the form below to order.</p> <p><span style="color: rgb(255, 0, 0);">Only click the submit button ONCE, as it may double charge you.</span></p> <form name="order" action="processorder.php" method="post"> <p><strong>Section 1 - Your Details (ALL FIELDS REQUIRED)</strong></p> <p>This section is used to get more information about you, the customer. We will use some of these details on your ticket, and will store them in our database. We respect your privacy, so </p> <p>Your Full Name:<br /> <input type="text" name="name" /><br /> <em>(will be used on your tickets</em><em>)</em></p> <p>Your Email Address:<br /> <input type="text" name="email" /><br /> <em>(we will send your ticket details to this email)</em></p> <p>Security Code:<br /> <input type="password" name="security" maxlength="5" /><br /> <em>(this will be used for enterance to the venue, and for future contact)</em></p> <p>Home Address:<br /> <textarea name="address"></textarea><br /> <em>(this is where your tickets will be delivered)</em></p> <p>PayPal Email Address:<br /> <input type="text" name="paypal" /><br /> <em>(this is just for verification, to speed up the approval process)</em></p> <hr /> <p><strong>Section 2 - Order Details</strong></p> <p>Please enter the quantity for each ticket type. The cost of one is displayed beside it.</p> <p>Adult: <input type="text" name="adult_t" size="3" maxlength="2" /> ' . $row['adult_price'] . '</p> <p>Concession: <input type="text" name="concession_t" size="3" maxlength="2" />' . $row['concession_price'] . '</p> <p><input type="submit" name="submit" value="Process Order" /></p> </form> <p> </p>'; //set page title $html = str_replace('{pagename}', 'Ticketing Home', $html); //replace for the content $html = str_replace('{content}', $content, $html); //provide content - packs up all the above changes and adds it to your theme. important!!!! echo $html; ?> What I now need is for the script to calculate the total ($concession_price * concession_t + $adult_price * adult_t), and convert it to a PayPal button. It should also save all the details from the form into the DB, in a table called "orders" with the following names: id (order ID) * name (orderer name) email (orderer email) address (orderer home address) security (orderers security code) paypal (orderers paypal address) eventname (name of event - linked from ID) adult_tix (no of adult tickets) concess_tix (no of concession tickets) cost (total cost) paid (automatically 0) * Ones marked with a * are auto generated. the rest are from the inputs. Anyone able to help? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/163528-calculate-total-save-to-db-and-proceed-to-paypal/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.