Jump to content

[SOLVED] Best way to create an invoice after submit..


A JM

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

$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
Share on other sites

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.  :D

 

A JM,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.