944,051 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 543
  • PHP RSS
Oct 13th, 2009
0

passing varaible between pages ussing sessions

Expand Post »
Hello, I have 2 php forms, the first that takes the input and sends it to the second form which checks to see if the fields are empty.

What I have to do is if both fields are not entered is return to the main page and highlight the field/s that is not fill with an asterix, If one of the fields was entered I need to return that value to the textbox on the first page and then link back to the first page to enter in the missing field.

here is the first page input.php
PHP Syntax (Toggle Plain Text)
  1. $asterixFirst = "";
  2. $asterixLast = "";
  3. // check for asterix value
  4. if ($checkFirst == false)
  5. {
  6. $asterixFirst = "* required";
  7. }
  8. else
  9. {
  10. $asterixFirst = "";
  11. }
  12. if ($checkLast == false)
  13. {
  14. $asterixLast = "* required";
  15. }
  16. else
  17. {
  18. $asterixLast = "";
  19. }
  20.  
  21.  
  22. echo "<form action=\"inputcheck1.php\" method=\"post\">";
  23. echo "<p>Enter first name: <input type=\"text\" name=\"first\" />", $asterixFirst, "</p>";
  24. echo "<p>Enter last name: <input type=\"text\" name=\"last\"/>", $asterixLast, "</p>";
  25. echo "<input type=\"submit\" value=\"Process\"/>";
  26.  
  27. echo "</form>";
  28. ?>
  29. </body>
  30. </html>

here is the 2nd page

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if ((checkFirst() == false) && (checkLast() == true))
  3. {
  4. echo "First name needed";
  5. }
  6. elseif ((checkFirst() == true) && (checkLast() == false))
  7. {
  8. echo "Last name needed";
  9. }
  10. elseif ((checkFirst() == false) && (checkLast() == false))
  11. {
  12. echo "Both fields need filing";
  13. }
  14. else
  15. {
  16. echo "First Name: ", $_POST['first'];
  17. echo "<p>Last Name: ", $_POST['last'], "</p>";
  18. echo "<a href=\"emptyinput1.php\">return to main page</a>";
  19. }
  20. ?>
  21.  
  22. <?php
  23. function checkFirst()
  24. {
  25. $_POST['first'] = trim($_POST['first']);
  26. if (isset($_POST['first']) && $_POST['first'] !== '')
  27. {
  28. //echo "First Name: ", $_POST['first'];
  29. return true;
  30. }
  31. else
  32. {
  33. return false;
  34. }
  35. }
  36.  
  37. function checkLast()
  38. {
  39. $_POST['last'] = trim($_POST['last']);
  40. if (isset($_POST['last']) && $_POST['last'] !== '')
  41. {
  42. //echo "<p>Last Name: ", $_POST['last'], "</p>";
  43. return true;
  44. }
  45. else
  46. {
  47. return false;
  48. }
  49. }
  50. ?>

I have the checks working ok, just not sure how to pass the value of a entered field gathered by form 2 back to that field on the first form and then how to send the asterix check either.

I assuming it needs to be done using the $_SESSION command somehow.

any help much appreciated
Last edited by mr_scooby; Oct 13th, 2009 at 3:48 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
mr_scooby is offline Offline
58 posts
since Feb 2008
Oct 13th, 2009
1
Re: passing varaible between pages ussing sessions
Insert this at the top of both pages:
php Syntax (Toggle Plain Text)
  1. if (! session_id())
  2. session_start();

Then you can use
php Syntax (Toggle Plain Text)
  1. $_SESSION['first'] = $_POST['first'];
in the second file. In the first file you can use:
php Syntax (Toggle Plain Text)
  1. if (isset($_SESSION['first']))
  2. // first name was set by second page, you can use it
Last edited by pritaeas; Oct 13th, 2009 at 4:39 am.
Sponsor
Featured Poster
Reputation Points: 556
Solved Threads: 732
Bite my shiny metal ass!
pritaeas is offline Offline
4,196 posts
since Jul 2006
Oct 13th, 2009
0
Re: passing varaible between pages ussing sessions
awesome, did the job exactly thank you.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
mr_scooby is offline Offline
58 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Profile user page
Next Thread in PHP Forum Timeline: Update query with syntax error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC