Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   releasing a veriable? (http://www.programmingforums.org/showthread.php?t=13772)

Kelvoron Aug 15th, 2007 8:20 PM

releasing a veriable?
 
hey guys i am playing around with php trying to get a head start as i will be having a class on it in three weeks and i was wondering how to release a veriable? meaning i have a form you input what will eventuly become a pass word right now it is dog, and when you input dog, for the time beeing it says thank you for loging in, any other time it says sorry your not in the database, the problem i am having is once you hit submit and dog is the veriable $pass it will continue to stay as $pass when you refresh it. wich is a good thing in the long run, but i need to be able to release the veriable, or log out if you will.

heres my code:
:

<font class="phpexample">
<form method="post">
Yourname:<input type="text" name="pass">
<input type="submit" value="submit">
</form>
<?
$pass=$_POST['pass'];
if($pass == "dog")
{
print("Thank you for loging in");
}
else{
print("sorry not in data base");
}
?>


thanks in advanced

Wizard1988 Aug 15th, 2007 8:33 PM

You would normally want to have the login form submit to a new page. You don't really need to release anything, just set a session variable that the user is logged in and send them to whatever page necessary.

Kelvoron Aug 15th, 2007 8:37 PM

okay. thanks

titaniumdecoy Aug 15th, 2007 10:06 PM

To answer your question, you can use the unset function. Whether the data will be automatically resubmitted when the page is refreshed is browser-depended; in my browser (Safari on Mac OS X) it is not.

Your form should have an action attribute; you can set it to the name of the current page to replicate the current behavior:

:

<form method="post" action="filename.php" name="nameform">
Note that your form should also have a name attribute ("nameform" in the example above) to facilitate scripting.

Also note that the <font> tag is deprecated (use <div> or <span> instead). Additionally, you should close all tags, even those that do not require separate closing tags; for example:

:

<input type="submit" value="submit" />
Finally, you should check whether the form has been submit before printing a failure or success message by using the isset function; similarly, you may not want to display the form if the name is successfully found in the "database".


All times are GMT -5. The time now is 12:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC