| | |
displaying a form within a php script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
Solved Threads: 0
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:
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.
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:
PHP Syntax (Toggle Plain Text)
<? /** * 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>] " ."[<a href=\"useredit.php\">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href=\"admin/admin.php\">Admin Center</a>] "; } 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 <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 ...
> 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."
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
Solved Threads: 0
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?
PHP Syntax (Toggle Plain Text)
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?
Last edited by justinmyoung; Apr 4th, 2009 at 6:44 pm.
Change that line to:
Consider using double quotation marks ...
You can't prevent from submitting data to a PHP script ...
PHP Syntax (Toggle Plain Text)
<form method="post" action="<?php echo $PHP_SELF;?>">
Consider using double quotation marks ...
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."
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
•
•
•
•
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:
PHP Syntax (Toggle Plain Text)
<? /** * 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>] " ."[<a href=\"useredit.php\">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href=\"admin/admin.php\">Admin Center</a>] "; } 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 <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.
[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.
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
Solved Threads: 0
Ok, I was able to come up with this:
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
PHP Syntax (Toggle Plain Text)
} 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
![]() |
Similar Threads
- simple ajax output not displaying (ASP.NET)
- php.ini confusion (PHP)
- Firefox Compatibility help with script (JavaScript / DHTML / AJAX)
- Listbox is not displaying the correct information if at all (PHP)
- pagination not displaying results (PHP)
- Loading image to HTML (JavaScript / DHTML / AJAX)
- Please help with email form script (PHP)
Other Threads in the PHP Forum
- Previous Thread: Trying to open URL's from MySQL database
- Next Thread: how do i find out the row size in kb?
| Thread Tools | Search this Thread |
.htaccess ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl customizableitems database date delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube






