esoteric Posted August 1, 2011 Share Posted August 1, 2011 Hi, I'm trying to 'automate' my site a little to take out some of the manual work. I currently have an order system in which a customer will browse and add items to the cart, when finished the contents of the cart and customer details are emailed to me via a form. I then have to create a new .php page which is an invoice and allows the person to pay. Is there anyway to create a new .php upon submitting a form? It would need to contain the data below. <?php // i have some php code here ?> <!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=utf-8" /> <title>xxxxxxxxxxxx - Invoice</title> // few .css and a script here </head> <body> <table width="612" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"><p><img src="../../images/catalogue/orderstatus_title.png" width="400" height="100" alt="order"><br> </p></td> </tr> <tr> <td align="center"><hr /></td> </tr> <tr> <td align="center"><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><?php // unique customer order number $sql="SELECT * FROM orderTable WHERE orderNum = 'xxxxxxxx' AND userId = '{$_SESSION['user_id']}'"; if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { ?></td> </tr> <tr> <td width="36%" bgcolor="#CDE3F3">Customer name</td> <td width="64%" align="center" bgcolor="#CDE3F3"><input name="textfield7" type="text" disabled="disabled" id="textfield7" value="<?php echo $req['lastName'];?>, <?php echo $req['firstName'];?>"></td> </tr> <tr> <td bgcolor="#CDE3F3">Order Date</td> <td align="center" bgcolor="#CDE3F3"><input name="textfield" type="text" disabled="disabled" id="textfield" value="<?php echo $req['orderDate']; ?> "/></td> </tr> <tr> <td bgcolor="#CDE3F3">Order Number</td> <td align="center" bgcolor="#CDE3F3"><input name="textfield8" type="text" disabled="disabled" id="textfield8" value="<?php echo $req['orderNum'];?>"></td> </tr> <tr> <td colspan="2"><span class="description"> <?php } } else { echo "Your Invoice could not be found! Please try again later."; } } else { echo "Query failed ".mysql_error(); } ?> </span></td> </tr> </table></td> </tr> <tr> <td align="center"><p class="loginform"><span class="errorMessage">If the above details are correct, enter your username and password below.<br> <a href="xxxxxxxxxx">Not you?</a> Please check your order number and try again. </span><br> <br> </p></td> </tr> <tr> <td align="center"><hr /></td> </tr> <tr> <td align="center"><form name="form" method="post" action="<?php echo $_SERVER['../../login/PHP_SELF']; ?>"> <p> <label for="txtUsername">Username:</label> <br /> <input type="text" title="Enter your Username" name="txtUsername" /> </p> <p> <label for="txtpassword">Password:</label> <br /> <input type="password" title="Enter your password" name="txtPassword" /> </p> <p> <input type="submit" onclick="confirm_log_in()" onclick="return log_in()" name="Submit" value="Login" /> </p> </form></td> </tr> <tr> <td align="center" class="credit">You should have received an email containing your username and password after your order has been processed. Please allow up to 24 hours after submitting your order to receive this email. Keep your details safe as you will need them each time you want to access this page.<br /> <br /> If you still have not received your details or cannot log in then please <a href="xxxxxxxxxxxx/contact-us">contact us</a>. By clicking 'Login' you agree that you are the customer stated above or have permission from the customer. For security your IP address will be logged.</td> </tr> <tr> <td><hr /></td> </tr> <tr> <td><?php } else { ?></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" align="center"><p>Below you will find details regarding your order, please check everything is correct BEFORE you submit payment. <br /> If you need to amend anything please <a href="xxxxxxxxxxxxxxxxcontact-us">contact us</a><br> <br> <?php // unique customer order number $sql="SELECT * FROM orderTable WHERE orderNum = 'xxxxxxxxxxxx' AND userId = '{$_SESSION['user_id']}'"; if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { ?> </p></td> </tr> <tr> <td width="100%" colspan="2" align="center"><textarea name="textarea" id="textarea" cols="90" rows="20"><?php echo $req['strMessageBody']; ?></textarea> <br></td> </tr> <tr> <td colspan="2" align="center"><hr /></td> </tr> <tr> <td colspan="2" align="center"><img src="../../images/catalogue/payment_title.png" width="400" height="100" alt="payment"></td> </tr> <tr> <td colspan="2" align="center"><br></td> </tr> <tr> <td colspan="2" align="center"><form id="form1" name="form1" method="post" action="xxxxxxxxxxxxxxxxPayment_Information.php"> <table width="40%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="240" align="center" bgcolor="#CDE3F3"><p>Total in GBP(£)</p></td> <td width="190"><input name="amount" type="text" id="amount" value="<?php echo $req['total'];?>" readonly="readonly" /></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="submit" id="submit" value="Submit" /> </label></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2" align="center">To confirm invoice amount, please press the submit button above, once your payment has been received your order can begin to be built. <br /> <br /> </td> </tr> <tr> <td colspan="2" align="center"><span class="description"> <?php } } else { echo "Your Invoice could not be found! Please try again later."; } } else { echo "Query failed ".mysql_error(); } ?> </span></td> </tr> </table> <p> </p></td> </tr> </table></td> </tr> <tr> <td><?php } ?></td> </tr> </table> </body> </html> as you can see above all this page really does is list the products and few customer details. The point of the page is because i have a 'pay' link at the bottom which direct to paypal. The main problem i can see is the script call from a unique table in mysql database SELECT * FROM orderTable WHERE orderNum = 'xxxxxxxxxxxx' Each page i have to manually change this at the moment so i don't know if its even possible to change this according to the invoice number being sent. Sorry about the long post, hope you understand my goal. Thank you in advance. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 1, 2011 Share Posted August 1, 2011 You would not create a new PHP file for the invoice. You should store the order information in the database then dynamically create the invoice page using that data. So, you only need one PHP script to display the invoice for any order. I am not going to read through your code above, but the basic implementation would require that you pass the order id to the invoice page. Then use that value to query the database and create the page. Without seeing your exact database structure I can only provide some mock code (and I do not want to see your database structure - I am not going to walk you through the process of creating an order management site via a forum post). But, your database *should* contain at least an "order" table to store the basic info about the order: order id, user, date, shipping costs, etc. Then there should be an associated table of products contained in the order containing the individual product details. Both of those tables should actually have foreign keys to other associative tables (users, product, etc.) but I will leave that out of the example Here is a very rough example script. There would still be a lot to do, but this should give you something to build upon <?php //Get the passed order id $orderID = (isset($_GET['order_id'])) ? intval($_GET['order_id']) : 0; //Create/run query to get the invoice data $query = "SELECT orders.user, orders.date, orders.shipping, order.shipping_address, orders.tax, order_prod.product, order_prod.qty, order_prod.price_per_unit WHERE orders.order_id = {$orderID}"; $result = mysql_query($query); if(!mysql_num_rows($result)) { echo "No order found for order id '{$orderID}'."; } else { //Process the data for generating the invoice $orderUser = false; //Set var as flag to only process common order info once $subtotal = 0; //Var to calculate order subtotal $orderDetails = ''; //Var to stare HTML output of order details while($row = mysql_fetch_assoc($result)) { //Create order specific info from first record if(!$orderUser) { $orderUser = $row['user']; $orderDate = $row['date']; $orderShipCost = $row['shipping']; $orderShipAddr = $row['shipping_address']; $orderTax = $row['tax']; } //Create order details $productTotal = ($row['qty'] * $row['price_per_unit']); $orderDetails .= " <tr>\n"; $orderDetails .= " <td>{$row['product']}</td>\n"; $orderDetails .= " <td>{$row['qty']}</td>\n"; $orderDetails .= " <td>{$row['price_per_unit']}</td>\n"; $orderDetails .= " <td>{$productTotal}</td>\n"; $orderDetails .= " <tr>\n"; //Increase order subtotal $subtotal += $productTotal; } } ?> <html> <head></head> <body> Order date: <?php echo $orderDate; ?> <br><br> Ordered by: <?php echo $orderUser; ?> <br><br> Shipping Address: <?php echo $orderShipAddr; ?> <br><br> Order Details:<br> <table border="1"> <tr> <th>Product name</th> <th>Quantity</th> <th>Per Unit</th> <th>Price</th> </tr> <?php echo $orderDetails; ?> </table> <br><br> Subtotal: <?php echo $orderSubtotal; ?><br> Shipping: <?php echo $orderShipCost; ?><br> Tax: <?php echo $orderTax; ?><br> Total: <?php echo $orderTotal; ?><br> </body> </html> Quote Link to comment 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.