A JM Posted May 13, 2009 Share Posted May 13, 2009 What is the best way to create an Invoice/Confirmation page after a form has submitted my data to a mySQL database? Should I query the database based upon some field and retrieve the information or pass the information from the form page after the submit to the new page? Can someone help me get started on this.. I'm still getting to know php and I believe using $SESSION and an array might be the way to go. Thanks. A JM, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/ Share on other sites More sharing options...
BobcatM Posted May 13, 2009 Share Posted May 13, 2009 Should I query the database based upon some field and retrieve the information or pass the information from the form page after the submit to the new page? You can do either, but the later would be the best bet unless you have a auto incr value you need to know what is. $date=$_POST['date']; $name=$_POST['name']; When you pass the variables just echo them out.. echo ("<h3>$name</h3>"); echo "<br>"; echo ("$date"); Hope that helps... Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833425 Share on other sites More sharing options...
A JM Posted May 13, 2009 Author Share Posted May 13, 2009 I do have an auto increment item... so I assume this will need to come directly from the DB... Since the session stores information from the page how does it store text fields - is it by the name of the textbox? I assume I could query the DB for the Invoice number on the page load unless there would be a better way of doing it? Thanks, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833433 Share on other sites More sharing options...
BobcatM Posted May 13, 2009 Share Posted May 13, 2009 I do have an auto increment item... so I assume this will need to come directly from the DB... That's only if you need to know what that number is and want to display it, like a Purchase Order number. If that's the case, something like this would tell you the last number entered. $sql = "SELECT po FROM polog ORDER BY po desc limit 1"; $result = mysql_query($sql); $po_no = mysql_result($result,"po"); echo ("<h2> $po_no </h2>"); how does it store text fields - is it by the name of the textbox? Like the one below it would be $name <input type="text" name="name"> Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833443 Share on other sites More sharing options...
A JM Posted May 13, 2009 Author Share Posted May 13, 2009 Thanks bobcatM that confirms my assumptions. My page that submits to the DB has a session set and does not have an unset. //initialize the session if (!isset($_SESSION)) { session_start(); } So, does that mean that after I submit the records to the DB and I redirect to my invoice page that the fields will be available until I unset the session or leave the site? Thanks, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833479 Share on other sites More sharing options...
BobcatM Posted May 13, 2009 Share Posted May 13, 2009 So, does that mean that after I submit the records to the DB and I redirect to my invoice page that the fields will be available until I unset the session or leave the site? That is correct. Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833505 Share on other sites More sharing options...
BobcatM Posted May 13, 2009 Share Posted May 13, 2009 Also if you want to destroy the session after you have displayed the page this would work. <?php session_destroy(); ?> Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833508 Share on other sites More sharing options...
Mchl Posted May 13, 2009 Share Posted May 13, 2009 I used to do this by transferring data from the form to invoice script using session. However last week I reworked the system to use data stored in database. Why? Because now I can use same code to print invoice when data is inserted, and when there is a need to retrieve one from archive. Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833515 Share on other sites More sharing options...
A JM Posted May 13, 2009 Author Share Posted May 13, 2009 That totally makes sense Mchl - essentially that would be a DB query based upon the Invoice number from the $_SESSION I assume, correct? It's making more sense now. After my user submits the form and if I don't unset the $_SESSION what happens if they hit the back button - does that create a problem since the data still exists in the $_SESSION? Also, do you guys mind if I ask a question about printing an Invoice/Confirmation. Do you just use the File/Print option in the browser or is there a better way to print off an Invoice/Confirmation? Thanks for all the input. A JM, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833520 Share on other sites More sharing options...
Mchl Posted May 13, 2009 Share Posted May 13, 2009 If using 'back' button is a problem or not depends on how you handle session data. In most cases it should not, but to be sure just remove unneeded data from session. I use FPDF to generate PDF invoices. Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833528 Share on other sites More sharing options...
A JM Posted May 14, 2009 Author Share Posted May 14, 2009 $date=$_POST['date']; $name=$_POST['name']; When you pass the variables just echo them out.. echo ("<h3>$name</h3>"); echo "<br>"; echo ("$date"); Hope that helps... Not having any luck at the moment..? I'm using this on my submission form which I believe I need - $clnt_name = $_POST['clnt_name']; and on my Invoice/confirmation - <?php echo ("$clnt_name"); ?> But getting nothing but a blank, any thoughts? A JM, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833672 Share on other sites More sharing options...
A JM Posted May 14, 2009 Author Share Posted May 14, 2009 I took your advice Mchl and decided to go with a query to pull the results directly from the DB. I have another question regarding the auto increment field that I will post in another question. Thanks for the help with this one guys. A JM, Link to comment https://forums.phpfreaks.com/topic/158000-solved-best-way-to-create-an-invoice-after-submit/#findComment-833704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.