displaying a form within a php script

Reply

Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

displaying a form within a php script

 
0
  #1
Apr 4th, 2009
I'm working on implementing a php registration/login script. When a user registers and then login - they are directed to a page that I would like to display a form, such as you would see in a contest. The person would fill out the form, entering the information into the database under his/her id's.

The trouble I'm finding is scripting a form within the php. I have not yet entered the fields into the database regarding the contest input fields...

Here's the php:

  1.  
  2. <?
  3. /**
  4.  * Main.php
  5.  *
  6.  * This is an example of the main page of a website. Here
  7.  * users will be able to login. However, like on most sites
  8.  * the login form doesn't just have to be on the main page,
  9.  * but re-appear on subsequent pages, depending on whether
  10.  * the user has logged in or not.
  11.  *
  12.  * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
  13.  * Last Updated: August 26, 2004
  14.  */
  15. include("include/session.php");
  16. ?>
  17.  
  18. <html>
  19. <title>Jpmaster77's Login Script</title>
  20. <body>
  21.  
  22. <table>
  23. <tr><td>
  24.  
  25.  
  26. <?
  27. /**
  28. * User has already logged in, so display relavent links, including
  29. * a link to the admin center if the user is an administrator.
  30. */
  31. if($session->logged_in){
  32. echo "<h1>Logged In</h1>";
  33. echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
  34. ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
  35. ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
  36. if($session->isAdmin()){
  37. echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
  38. }
  39. echo "[<a href=\"process.php\">Logout</a>]";
  40.  
  41. /**
  42.  
  43. enter form here. this form will only be seen by those who are logged in....
  44.  
  45.  
  46. */
  47.  
  48.  
  49. }
  50. else{
  51. ?>
  52.  
  53. <h1>Login</h1>
  54. <?
  55. /**
  56. * User not logged in, display the login form.
  57. * If user has already tried to login, but errors were
  58. * found, display the total number of errors.
  59. * If errors occurred, they will be displayed.
  60. */
  61. if($form->num_errors > 0){
  62. echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
  63. }
  64. ?>
  65. <form action="process.php" method="POST">
  66. <table align="left" border="0" cellspacing="0" cellpadding="3">
  67. <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
  68. <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
  69. <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
  70. <font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
  71. <input type="hidden" name="sublogin" value="1">
  72. <input type="submit" value="Login"></td></tr>
  73. <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
  74. <tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
  75. </table>
  76. </form>
  77.  
  78. <?
  79. }
  80.  
  81. /**
  82. * Just a little page footer, tells how many registered members
  83. * there are, how many users currently logged in and viewing site,
  84. * and how many guests viewing site. Active users are displayed,
  85. * with link to their user information.
  86. */
  87. echo "</td></tr><tr><td align=\"center\"><br><br>";
  88. echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
  89. echo "There are $database->num_active_users registered members and ";
  90. echo "$database->num_active_guests guests viewing the site.<br><br>";
  91.  
  92. include("include/view_active.php");
  93.  
  94. ?>
  95.  
  96.  
  97. </td></tr>
  98. </table>
  99. </body>
  100. </html>
  101.  

Can anyone help me? I just want fields like this:

1st place [ enter name here ]
2nd place [ enter name here ]
etc.

The key of course is that once this form is submitted that it goes to the correct person's name in the database...Thanks for any direction...or help.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: displaying a form within a php script

 
0
  #2
Apr 4th, 2009
To display a form from within a PHP script you can do the following:
> Use the echo-command to write the HTML-code (which is displaying the form) directly to the webpage
> You put the HTML code to view a form outside the PHP-tag(s)

You could also check out this page ...
Last edited by tux4life; Apr 4th, 2009 at 6:34 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #3
Apr 4th, 2009
I came up with this:

  1. echo "<form type='contest.php' method='POST'>
  2. 1st: <input type='text' name='first'><br><br>
  3. 2nd: <input type='text' name='second'><br><br>
  4. 3rd: <input type='text' name='three'><br><br>
  5. 4th: <input type='text' name='four'><br><br>
  6. 5th: <input type='text' name='five'><br><br>
  7. 6th: <input type='text' name='six'><br><br>
  8.  
  9. <input type='submit' name='submit' value='submit'>
  10. </form>";

How do I ensure that the submit will go only toward the person who is logged-in's id in the database?
Last edited by justinmyoung; Apr 4th, 2009 at 6:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: displaying a form within a php script

 
0
  #4
Apr 4th, 2009
Originally Posted by justinmyoung View Post
  1. echo "<form type='contest.php' method='POST'>
  2.  
Change that line to:
  1. <form method="post" action="<?php echo $PHP_SELF;?>">

Consider using double quotation marks ...

Originally Posted by justinmyoung View Post
I came up with this:
How do I ensure that the submit will go only toward the person who is logged-in's id in the database?
You can't prevent from submitting data to a PHP script ...
Last edited by tux4life; Apr 4th, 2009 at 7:00 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: displaying a form within a php script

 
0
  #5
Apr 5th, 2009
How do I ensure that the submit will go only toward the person who is logged-in's id in the database?
Pass logged person's id as a hidden form element. Use that id to update the table.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #6
Apr 5th, 2009
Originally Posted by justinmyoung View Post
I'm working on implementing a php registration/login script. When a user registers and then login - they are directed to a page that I would like to display a form, such as you would see in a contest. The person would fill out the form, entering the information into the database under his/her id's.

The trouble I'm finding is scripting a form within the php. I have not yet entered the fields into the database regarding the contest input fields...

Here's the php:

  1.  
  2. <?
  3. /**
  4.  * Main.php
  5.  *
  6.  * This is an example of the main page of a website. Here
  7.  * users will be able to login. However, like on most sites
  8.  * the login form doesn't just have to be on the main page,
  9.  * but re-appear on subsequent pages, depending on whether
  10.  * the user has logged in or not.
  11.  *
  12.  * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
  13.  * Last Updated: August 26, 2004
  14.  */
  15. include("include/session.php");
  16. ?>
  17.  
  18. <html>
  19. <title>Jpmaster77's Login Script</title>
  20. <body>
  21.  
  22. <table>
  23. <tr><td>
  24.  
  25.  
  26. <?
  27. /**
  28. * User has already logged in, so display relavent links, including
  29. * a link to the admin center if the user is an administrator.
  30. */
  31. if($session->logged_in){
  32. echo "<h1>Logged In</h1>";
  33. echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
  34. ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
  35. ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
  36. if($session->isAdmin()){
  37. echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
  38. }
  39. echo "[<a href=\"process.php\">Logout</a>]";
  40.  
  41. /**
  42.  
  43. enter form here. this form will only be seen by those who are logged in....
  44.  
  45.  
  46. */
  47.  
  48.  
  49. }
  50. else{
  51. ?>
  52.  
  53. <h1>Login</h1>
  54. <?
  55. /**
  56. * User not logged in, display the login form.
  57. * If user has already tried to login, but errors were
  58. * found, display the total number of errors.
  59. * If errors occurred, they will be displayed.
  60. */
  61. if($form->num_errors > 0){
  62. echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
  63. }
  64. ?>
  65. <form action="process.php" method="POST">
  66. <table align="left" border="0" cellspacing="0" cellpadding="3">
  67. <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
  68. <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
  69. <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
  70. <font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
  71. <input type="hidden" name="sublogin" value="1">
  72. <input type="submit" value="Login"></td></tr>
  73. <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
  74. <tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
  75. </table>
  76. </form>
  77.  
  78. <?
  79. }
  80.  
  81. /**
  82. * Just a little page footer, tells how many registered members
  83. * there are, how many users currently logged in and viewing site,
  84. * and how many guests viewing site. Active users are displayed,
  85. * with link to their user information.
  86. */
  87. echo "</td></tr><tr><td align=\"center\"><br><br>";
  88. echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
  89. echo "There are $database->num_active_users registered members and ";
  90. echo "$database->num_active_guests guests viewing the site.<br><br>";
  91.  
  92. include("include/view_active.php");
  93.  
  94. ?>
  95.  
  96.  
  97. </td></tr>
  98. </table>
  99. </body>
  100. </html>
  101.  

Can anyone help me? I just want fields like this:

1st place [ enter name here ]
2nd place [ enter name here ]
etc.

The key of course is that once this form is submitted that it goes to the correct person's name in the database...Thanks for any direction...or help.



[ICODE]In jpmaster77 code....you have to call the process.php put it in session command inside the process ex. $session->subrank(user,rank); and run the database.php included files.

1. copy that form or save as new name.
2. edit the textbox properties according to what you want.
3. change the "sublogin" name inside the form snippet <input type="hidden" name="sublogin" value="1"> name it "myranking". <input type="hidden" name="myranking" value="1">
4. put "mayranking" inside the process and use "$session->username" in your procRanking() function to make sure it is the current user.
"

//PROCESS.PHP

 /* User submitted login form */
      if(isset($_POST['sublogin'])){
         $this->procLogin();
      }
      /* User submitted registration form */
      else if(isset($_POST['subjoin'])){
         $this->procRegister();
      }
   /* User submitted registration form */ ------------> HERE TO TRIGGER your POST page
      else if(isset($_POST['myranking'])){
         $this->procRanking();
      }


function procRanking(){
      global $session, $form;
      /* Registration attempt */

      $db_user = $session->username;  
      $session->putRanking($db_user, $_POST['rank']);

6. open the session.php then add...the function

//SESSION.PHP

 function putRanking($txtone, $txttwo){
      global $database, $form;  //The database and form object
   
          $database->updateUserField(youronetxtbox,"yourcolumninsidethedatabase",md5($subnewpass));

you can create your own function in database.


//DATABASE.PHP

This is the function inside the database.php modified this if you are updating field.

   function updateUserField($username, $field, $value){
      $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
      return mysql_query($q, $this->connection);
   }  

i don't know if you want to update field or adding new records.

you can download my PHP Login System w/ 5 Levels of Security for more info....http://sourceforge.net/projects/phploginsystemw/

You can give donation if you want....
Last edited by rm_daniweb; Apr 5th, 2009 at 10:10 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #7
Apr 14th, 2009
Thanks very much...I'll check out your script, and if I can manage to understand it, and get it to work - I will donate something. Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #8
Apr 14th, 2009
hmmm...not to be a total idiot, but not sure how to do this...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #9
Apr 14th, 2009
Ok, my first problem is I can't write a basic form within an echo statement.

Could someone offer an example of that?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: displaying a form within a php script

 
0
  #10
Apr 14th, 2009
Ok, I was able to come up with this:

  1. } elseif (($session->logged_in) && ($session->isAdmin())) {
  2. echo "<h1>Logged In</h1>";
  3. echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
  4. ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] "
  5. ."[<a href=\"master_register.php?user=$session->username\">Add Master</a>] "
  6. ."[<a href=\"useredit.php\">Edit Account</a>] ";
  7. echo "[<a href=\"admin/admin.php\">Admin Center</a>] ";
  8. echo "[<a href=\"process.php\">Logout</a>]";
  9.  
  10. echo "<h1>Predict Order of Finish</h1>";
  11. echo "<br/>";
  12. echo "<form action='process.php' method='POST'>";
  13. echo "1st: <input type='text' name='name' /><br/><br/>";
  14. echo "2nd: <input type='text' name='name' /><br/><br/>";
  15. echo "3rd: <input type='text' name='name' /><br/><br/>";
  16. echo "4th: <input type='text' name='name' /><br/><br/>";
  17. echo "5th: <input type='text' name='name' /><br/><br/>";
  18. echo "6th: <input type='text' name='name' /><br/><br/>";
  19. echo "7th: <input type='text' name='name' /><br/><br/>";
  20. echo "8th: <input type='text' name='name' /><br/><br/>";
  21. echo "9th: <input type='text' name='name' /><br/><br/>";
  22. echo "10th: <input type='text' name='name' /><br/><br/>";
  23. echo "</form>";
  24.  
  25. } else {

But am uncertain how to proceed with the goal being to allow each registrar the opportunity to make their picks unique to their registration details. So if Bob registers, then makes his picks, I have obviously make sure that Bob's picks go to his name in the database...

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC