PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 1:25 pm
Code: Select all
<b>Log In</b>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
<?
$password = "bnx4life";
if (isset($_POST['txtPassword'])) {
if($_POST['txtPassword'] != $password) {
// tell them to log-in again
} else {
// login is good
}
?>
/edit - this isnt what you want, but you should be able to correct your code with it
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 1:37 pm
This is what I got, but I keep getting an error.
Code: Select all
<?php
$password = "bnx4life";
if ($_POST['txtPassword'] != $password) {
?>
<b>Log In</b>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
<?php
}
else {
?>
<p>BnX members please log in.</p>
<?php
}
?>
<?php
if (isset($_POST['txtPassword'])) {
if($_POST['txtPassword'] != $password) {
// tell them to log-in again
} else {
// login is good
}
?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 3:22 pm
i hope I didnt confuse you.
Code: Select all
<?php
if (isset($_POST['Submit'])) {
$password = "bnx4life";
$pass = $_POST['txtPassword'];
if ($password == $pass) {
// login was correct
} else {
// login was incorrect
} else {
?>
<b>Log In</b>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
this should work. if not, if you get an error please post the error. It'll help us try to help you
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 5:57 pm
Parse error: parse error in /home/krunk/public_html/BnX/index.php on line 14
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Jun 06, 2004 6:00 pm
add this to the end.
<?
} // to end the else statement
?>
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Sun Jun 06, 2004 9:13 pm
Same error again.
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Sun Jun 06, 2004 9:30 pm
You cannot have two else statements following each other, tim probably meant to use elseif () instead for the middle one (or some other kind of code sequence / order). Two } else { blocks would cause a parser error.
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Sun Jun 06, 2004 9:36 pm
Yes you can. He opened two if statements.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Mon Jun 07, 2004 2:50 am
Try
Code: Select all
<?php
$password = "bnx4life";
if ($_POST['txtPassword'] != $password) {
echo '<b>Log In</b>
<form name="form" method="post" action="'.$_SERVER["PHP_SELF"].'">
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>';
}
else {
header("Location: http://forums.devnetwork.net");
}
?>
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Mon Jun 07, 2004 5:32 am
Yes you can. He opened two if statements.
So he did
Damn that's a good argument for indenting your code!
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Mon Jun 07, 2004 2:23 pm
Thanks alot! Works great.
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Mon Jun 07, 2004 3:37 pm
Great! What I'd advise: NEVER(!) open an IF-statement, then "end" PHP with ?> write some HTML and the "open" PHP again with <?php
The parser will be somewhat confused if you do that, your code becomes extremely untidy and it's hard for others to understand what's going on. Try working towards solutions where you actually have an HTML page and only show the results of your PHP-functions. That's a first step towards seperating "logic" and view (your HTML).
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Mon Jun 07, 2004 6:11 pm
yeah I did open two if statements
i'm not that dumb... I meant to show him a way to do it, i wouldnt end my code like that either patrik.
I would echo out the html form if it was me
=]
glad he got it working tho