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:

<?
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 26, 2004
 */
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<table>
<tr><td>


<?
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
   
/**

enter form here.  this form will only be seen by those who are logged in....


 */

   
   }
else{
?>

<h1>Login</h1>
<?
/**
 * User not logged in, display the login form.
 * If user has already tried to login, but errors were
 * found, display the total number of errors.
 * If errors occurred, they will be displayed.
 */
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<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>
<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>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
</table>
</form>

<?
}

/**
 * Just a little page footer, tells how many registered members
 * there are, how many users currently logged in and viewing site,
 * and how many guests viewing site. Active users are displayed,
 * with link to their user information.
 */
echo "</td></tr><tr><td align=\"center\"><br><br>";
echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
echo "There are $database->num_active_users registered members and ";
echo "$database->num_active_guests guests viewing the site.<br><br>";

include("include/view_active.php");

?>


</td></tr>
</table>
</body>
</html>

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.

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

I came up with this:

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

<input type='submit' name='submit' value='submit'>
</form>";

How do I ensure that the submit will go only toward the person who is logged-in's id in the database?

echo "<form type='contest.php' method='POST'>

Change that line to:

<form method="post" action="<?php echo $PHP_SELF;?>">

Consider using double quotation marks ...

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

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

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:

<?
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 26, 2004
 */
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<table>
<tr><td>


<?
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
   
/**

enter form here.  this form will only be seen by those who are logged in....


 */

   
   }
else{
?>

<h1>Login</h1>
<?
/**
 * User not logged in, display the login form.
 * If user has already tried to login, but errors were
 * found, display the total number of errors.
 * If errors occurred, they will be displayed.
 */
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<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>
<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>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
</table>
</form>

<?
}

/**
 * Just a little page footer, tells how many registered members
 * there are, how many users currently logged in and viewing site,
 * and how many guests viewing site. Active users are displayed,
 * with link to their user information.
 */
echo "</td></tr><tr><td align=\"center\"><br><br>";
echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
echo "There are $database->num_active_users registered members and ";
echo "$database->num_active_guests guests viewing the site.<br><br>";

include("include/view_active.php");

?>


</td></tr>
</table>
</body>
</html>

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.

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.


[icode]

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

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.

hmmm...not to be a total idiot, but not sure how to do this...

Ok, my first problem is I can't write a basic form within an echo statement.

Could someone offer an example of that?

Ok, I was able to come up with this:

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

} 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

Here is where I'm at now...

<?
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 26, 2004
 */
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<table>
<tr><td>


<?
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
   
 echo "<h1>Predict Order of Finish</h1>";
	    echo "<br/>";
	    echo "<form method='post' action='<?php echo $PHP_SELF;?>'>"; 
	    echo "1st: <input type='text' name='one' /><br/><br/>";
	    echo "2nd: <input type='text' name='two' /><br/><br/>";
	    echo "3rd: <input type='text' name='three' /><br/><br/>";
	    echo "4th: <input type='text' name='four' /><br/><br/>";
	    echo "5th: <input type='text' name='five' /><br/><br/>";
	    echo "6th: <input type='text' name='six' /><br/><br/>";
	    echo "7th: <input type='text' name='seven' /><br/><br/>";
	    echo "8th: <input type='text' name='eight' /><br/><br/>";
	    echo "9th: <input type='text' name='nine' /><br/><br/>";
	    echo "10th: <input type='text' name='ten' /><br/><br/>";
	    echo "<input type='submit' value='submit'>";
		echo "</form>";



}
else{
?>

This is where I'm at now...

I modified the process.php form to look like this:

include("include/session.php");

class Process
{
   /* Class constructor */
function Process(){
      global $session;
      /* 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']);

Not sure what to do in the sessions.php...however...

The main form looks like this:

<?
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 26, 2004
 */
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<table>
<tr><td>


<?
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
   
 echo "<h1>Predict Order of Finish</h1>";
	    echo "<br/>";
	    echo "<form method='post' action='<?php echo $PHP_SELF;?>'>"; 
	    echo "1st: <input type='text' name='one' /><br/><br/>";
	    echo "2nd: <input type='text' name='two' /><br/><br/>";
	    echo "3rd: <input type='text' name='three' /><br/><br/>";
	    echo "4th: <input type='text' name='four' /><br/><br/>";
	    echo "5th: <input type='text' name='five' /><br/><br/>";
	    echo "6th: <input type='text' name='six' /><br/><br/>";
	    echo "7th: <input type='text' name='seven' /><br/><br/>";
	    echo "8th: <input type='text' name='eight' /><br/><br/>";
	    echo "9th: <input type='text' name='nine' /><br/><br/>";
	    echo "10th: <input type='text' name='ten' /><br/><br/>";
	    echo "<input type='hidden' name='myranking' value="1">";
	    echo "<input type='submit' value='submit'>";
		echo "</form>";



}
else{
?>
the action in FORM  is action="process.php"

echo "<h1>Predict Order of Finish</h1>";
	    echo "<br/>";
	    echo "<form method='post' action='process.php'; 
	    echo "1st: <input type='text' name='one' /><br/><br/>";
	    echo "2nd: <input type='text' name='two' /><br/><br/>";
	    echo "3rd: <input type='text' name='three' /><br/><br/>";
	    echo "4th: <input type='text' name='four' /><br/><br/>";
	    echo "5th: <input type='text' name='five' /><br/><br/>";
	    echo "6th: <input type='text' name='six' /><br/><br/>";
	    echo "7th: <input type='text' name='seven' /><br/><br/>";
	    echo "8th: <input type='text' name='eight' /><br/><br/>";
	    echo "9th: <input type='text' name='nine' /><br/><br/>";
	    echo "10th: <input type='text' name='ten' /><br/><br/>";
	    echo "<input type='hidden' name='myranking' value="1">";
	    echo "<input type='submit' value='submit'>";
		echo "</form>";



//PROCESS.PHP

  /* 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['one'],$_POST['two'],$_POST['three'],$_POST['four'],$_POST['five'],$_POST['six'],$_POST['seven'],$_POST['eight'],$_POST['nine'],$_POST['ten']);


//SESSION.PHP

function putRanking($db_user,$one,$two,$three,$four,$five,$six, $seven, $eight, $nine, $ten) {

[VALIDATION CODE HERE AND FORM ERROR MESSAGE IF YOU WANT]

$database->UpdateRanking($db_user,$one,$two,$three,$four,$five,$six, $seven, $eight, $nine, $ten)

}

//DATABASE.PHP

function UpdateRanking($db_user, $one,$two,$three,$four,$five,$six, $seven, $eight, $nine, $ten) {

INSERT INTO [TABLE] VALUES ('$db_user', '$one','$two','$three','$four','$five','$six', '$seven', '$eight', '$nine', '$ten');

}

that is the flow of that program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.