473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Order Processing Page

Hi All,

I have an assignment to complete and I just can't get it and I was hoping someone could help me out. What I need to do is:

Call the session_start function.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. ?>
Detect whether or not the name session variable has a value; if so, display name and age as text; if not, display the name and age input fields.

Expand|Select|Wrap|Line Numbers
  1. First name: <input type="text" name="fname" />  Age: <input type="text" name="age" />  <input type="submit" name="submit" value="Submit" />
  2.  
  3. <?php
  4. if (isset($_POST['submit'])) { 
  5. $_session['fname'] = $_POST['fname'];
  6. $_session['age'] = $_POST['age'];
  7. ?>
How can have the text fields replaced with the users Name and age after they type it in and submit the form? So, when they go back to the that page, they will already see their name and age printed out in place of the text fields. I also upload an image of what it is suppose to look like.

Thanks in advance for your help,
T
Attached Images
File Type: jpg User_info_after_submitted_form.jpg (7.5 KB, 109 views)
Aug 14 '13 #1
14 1569
Exequiel
288 256MB
Your fields and button must be placed inside the form tag. (<form method="post"> fields here!.. </form>)

Try to run this codes. . .
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3. ob_start();
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>Sample</title>
  10. </head>
  11.  
  12. <body>
  13.  
  14. <form method="post">
  15.     First name: <input type="text" name="fname" />  Age: <input type="text" name="age" />  <input type="submit" name="submit" value="Submit" />
  16. </form>
  17.  
  18. </body>
  19. </html>
  20. <?php 
  21.     if(isset($_POST['submit']))
  22.     {
  23.         $_SESSION['fname']=$_POST['fname'];
  24.         $_SESSION['age']=$_POST['age'];
  25.         //header('Location: page_to_go.php');
  26.         echo $_SESSION['fname'].' '.$_SESSION['age'];
  27.     }
  28. ?>
Aug 15 '13 #2
Hi Exequiel,

Thank you for the reply. I tried the code you suggested and it still doesn't work. Here's what I have:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3. ob_start();
  4. ?>
  5.  
  6. <?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  8. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9.  
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11. <head>
  12. <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
  13. <link rel="stylesheet" type="text/css" href="css/styles.css" />
  14. <script type="text/javascript" src="js/catalog.js"></script>
  15. <title>Scion tC Catalog</title>
  16. </head>
  17. <body>
  18. <a name="Top" id="Top"></a>
  19.  
  20. <form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" 
  21.  
  22. method="post">First name: <input type="text" name="fname" />  Age: <input type="text" name="age" />  <input 
  23.  
  24. type="submit" name="submit" value="Submit" /> <input type="button" onclick="formReset()" value="Reset form" />
  25. <br />
  26. <table class="table1">
  27. <tr>
  28. <th>Select</th>
  29. </tr>
  30. <tr>
  31. <td class="radio button"><input type="radio" name="scion" id="r1" value="You selected the 2010 Scion tC RS" /><br 
  32.  
  33. /></td>
  34. </tr>
  35. <tr>
  36. <td class="radio button"><input type="radio" name="scion" id="r2" value="You selected the 2012 Scion tC RS" /><br 
  37.  
  38. /></td>
  39. </tr>
  40. <tr>
  41. <td class="radio button"><input type="radio" name="scion" id="r3" value="You selected the 2013 Scion tC RS" /><br 
  42.  
  43. /></td>
  44. </tr>
  45. <tr>
  46. <td class="radio button"><input type="radio" name="scion" id="r4" value="You selected the 2014 Scion tC" /><br 
  47.  
  48. /></td>
  49. </tr>
  50. </table></form>
  51.  
  52. </body>
  53. </html>
  54.  
  55.  <?php 
  56.     if(isset($_POST['submit']))
  57.     {
  58.         $_SESSION['fname']=$_POST['fname'];
  59.         $_SESSION['age']=$_POST['age'];
  60.         //header('Location: catalog.php');
  61.         echo $_SESSION['fname'].' '.$_SESSION['age'];
  62.     }
  63. ?>
Aug 15 '13 #3
Rabbit
12,516 Expert Mod 8TB
You need to first check whether or not the name variable in the session is set and then choose what to output depending on if it's set or not.
Aug 15 '13 #4
If there's a session started, I need to have their name (fname) and age (age) displayed where the input text fields should be. If the session is not started, then the whole form should display with text fields for the user's input. Would it look something like this:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     if(isset($_POST['submit']))
  3.     {
  4.         $_SESSION['fname']=$_POST['fname'];
  5.         $_SESSION['age']=$_POST['age'];
  6.         //header('Location: catalog.php');
  7.         echo $_SESSION['fname'].' '.$_SESSION['age'];
  8.     }
  9.     if (isset($_POST['fname']) && ($_POST['age']))
  10.              $session = $_POST['fname'] && $_POST['age'];
  11.      session_start();
  12.      $_SESSION['fname'] && $_SESSION['age'] = $session;
  13. ?>
I'm sorry if this isn't close. I'm not a very good programmer and I'm still trying to learn.

Thanks,
T
Aug 15 '13 #5
Rabbit
12,516 Expert Mod 8TB
It needs to look more like this
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if(isset($_POST['submit'])) {
  3.    set your session variables
  4.    output your values
  5. } else {
  6.    output your form
  7. }
  8. ?>
Aug 15 '13 #6
I tried this:

Expand|Select|Wrap|Line Numbers
  1. <form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" method="post">
  2. <?php 
  3.     if(isset($_POST['submit'])) {
  4.  
  5. $_SESSION['fname']=$_POST['fname'];
  6. $_SESSION['age']=$_POST['age'];
  7.  
  8.     if(isset($_SESSION['fname'])) {
  9.       //header('Location: catalog.php');
  10.       echo $_SESSION['fname'].' '.$_SESSION['age'];}
  11.     else {
  12. echo 'First name: <input type="text" name="fname" />  Age: <input type="text" name="age" />  '; }
  13. }
  14. ?>
  15. <input type="submit" value="Submit" /> <input type="button" onclick="formReset()" value="Reset form" />
It's not displaying the text fields or the output. Am I getting close?

T
Aug 15 '13 #7
Rabbit
12,516 Expert Mod 8TB
That structure doesn't follow my example.
Aug 15 '13 #8
Ok, so what am I doing wrong? Please remember I trying to learn this. I very green when it comes to programming. Should it look like this:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     if(isset($_POST['submit'])) {
  3.  
  4. $_SESSION['fname']=$_POST['fname'];
  5. $_SESSION['age']=$_POST['age'];
  6.  
  7.     if(isset($_SESSION['fname'])) {
  8.       //header('Location: catalog.php');
  9.       echo $_SESSION['fname'].' '.$_SESSION['age'];}
  10.     else {
  11. echo '<form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" method="post"> 
  12.  
  13. First name: <input type="text" name="fname" />  Age: <input type="text" name="age" /> <input type="submit" value="Submit" /> 
  14.  
  15. <input type="button" onclick="formReset()" value="Reset form" />'; }
  16. }
  17. ?>
Aug 15 '13 #9
Rabbit
12,516 Expert Mod 8TB
Compare your structure to my structure.

To repeat, my structure is this:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if(isset($_POST['submit'])) {
  3.    set your session variables
  4.    output your values
  5. } else {
  6.    output your form
  7. }
  8. ?>
Your structure is this:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. if(isset($_POST['submit'])) {
  3.    set your session variables
  4.  
  5.    if(isset($_SESSION['fname'])) {
  6.       output your values
  7.    } else {
  8.       output your form
  9.    }
  10. }
  11. ?>
As your can see, your structure is not the same as mine.
Aug 15 '13 #10
So from what you said above, it should look like this?

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     if(isset($_POST['submit'])) {
  3. $_SESSION['fname']=$_POST['fname'];
  4. $_SESSION['age']=$_POST['age'];
  5. //header('Location: catalog.php');
  6. echo $_SESSION['fname'].' '.$_SESSION['age'];}
  7.     else {
  8. <form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" method="post"> First name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" value="Submit" /> <input type="button" onclick="formReset()" value="Reset form" />';
  9. }
  10. ?>
Aug 15 '13 #11
Rabbit
12,516 Expert Mod 8TB
That looks about right.

But I see another error, you didn't give your submit button a name. So it's not going to be set when it goes to check it.
Aug 15 '13 #12
Ok, I just tried the code above and it still doesn't show the name and age in replace of the text fields after the I go back to my catalog page. This is what I have:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.     if(isset($_POST['submit'])) {
  3. $_SESSION['fname']=$_POST['fname'];
  4. $_SESSION['age']=$_POST['age'];
  5. echo $_SESSION['fname'].' '.$_SESSION['age'];}
  6.     else {
  7. echo '<form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" method="post">';
  8. echo 'Name: <input type="text" name="fname" />'; 
  9. echo 'Age: <input type="text" name="age" />';
  10. echo '<input type="submit" name="submit" value="Submit" />';
  11. echo '<input type="button" onclick="formReset()" value="Reset form" />';
  12. }
  13. ?>
I really do appreciate your help with this.
T
Aug 15 '13 #13
Rabbit
12,516 Expert Mod 8TB
Works fine for me.

Assuming of course that everything else is correct. I am assuming all the code before and after this block of code is correct and that this code is in fact in the thankyou.php page. By which I mean you're submitting the page to itself.

And if by going back, you mean clicking the back button on your browser, that doesn't refresh the page.
Aug 15 '13 #14
Exequiel
288 256MB
@LugNut29
Its not still working because of the action on your form, action="thankyou.php". Your code that you replied to me is right, only the thankyou.php is the problem. If you try to remove the action="thankyou.php" on your form the code is working fine. but if you really want to display the session on thankyou.php try my code. I've created thankyou.php. can you post your thakyou.php ?
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3. ob_start();
  4. ?>
  5.  
  6. <?php 
  7.     echo $_SESSION['fname'].' '.$_SESSION['age'];
  8. ?>
  9.  
  10.  
Aug 16 '13 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: chints | last post by:
Hi, I have a very unique problem, i am submitting from a pdf form, when submitted goes to a asp page, which saves the data and redirects to a different page after saving the data. I am writing a...
1
by: shank | last post by:
I need advice on how to get started with this project. I want a page where a user can manually enter an order. Our users know our order# system and it's much easier to manually enter items as...
0
by: Matt | last post by:
I want to know how online order processing implemented? For example, the online shopping mall such as Amazon receives order, it will communicate with credit card company, and it will add that order...
1
by: Roy | last post by:
Anyone have any links and/or code samples demonstrating how this can be done? Current procedure is that john doe clicks an item on a datagrid and after however long, gets the info he wants. What...
6
by: CK | last post by:
I have a web page called PageOne.aspx which is supposed to do a long process but I don't need to show any results to the client, so I want to redirect the client to PageTwo.aspx right in the...
4
by: ~Maheshkumar.R | last post by:
hi groups, I have developed one FTP application in ASP.NET, When i upload a file, i want to show something on screen like " Please wait ...! Your file is being uploading........" As soon the file...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
2
by: Janusz Jezowicz | last post by:
Hello! I would like to have one page on the server, which would be a target processing page for a number of other aspx pages. E.g Processing page \portal_page.aspx Target pages
1
by: Tony Cheng | last post by:
Hello everybody, I got a aspx which have several user controls on it. My question is that what is the order of ASP.NET execute the page and user control ? does it like this : Page Init ->...
5
by: pattersonc | last post by:
Hello! I'm new to this forum and also new to using ASP and SQL and Access. I am in need of some help. I'm trying to make a database to help my football team. I've pretty much got the whole thing...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.