View previous topic :: View next topic |
Author |
Message |
mrpaul -
Joined: 23 Sep 2005 Posts: 18
|
Posted: Tue Sep 27, 2005 10:20 pm Post subject: else if |
|
|
Hey, i have made a news script that adds news to a page when submitted by a form, it check the passowrd witch works and then if it's wrong then it logs the ip witch is good, but if it's right it adds the news then logs the ip and thats not what i want,
the code,
<?php
$address = $_SERVER['REMOTE_ADDR'];
$addnews = "news.htm";
$news = $_POST['news'];
$title = $_POST['title'];
$name = $_POST['name'];
$pass = $_POST['password'];
$password = "addme";
$time = date ("H:i dS F");
$filey = fopen ("wrongpassowrds.html", "a+");
if ($pass == $password)
{
$file = fopen ( $addnews, "w") ;
fwrite ( $file, "<h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" ) ;
fclose ( $file ) ;
echo ( " Thank you for your news $name if ther are any errors in the spelling click back nwo to edit them, <p> <h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" );
}
# This is what it dose regardless of the password
else if ( $address != null);
{ fwrite ($filey, "<b>Time and date:</b> $time<br>") ; }
{ fwrite ($filey, "<b>IP Address:</b> $address<br><br><hr>") ;}
echo (" Wrong password! your ip ($address) the date and time ($time) have been logged. ");
?>
anyone know whats up? |
|
Back to top |
|
 |
roganty -
Joined: 08 Jun 2004 Posts: 357 Location: Bristol, UK
|
Posted: Tue Sep 27, 2005 11:00 pm Post subject: Re: else if |
|
|
Code: | <?php
$address = $_SERVER['REMOTE_ADDR'];
$addnews = "news.htm";
$news = $_POST['news'];
$title = $_POST['title'];
$name = $_POST['name'];
$pass = $_POST['password'];
$password = "addme";
$time = date ("H:i dS F");
$filey = fopen ("wrongpassowrds.html", "a+");
if ($pass == $password)
{
$file = fopen ( $addnews, "w") ;
fwrite ( $file, "<h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" ) ;
fclose ( $file ) ;
echo ( " Thank you for your news $name if ther are any errors in the spelling click back nwo to edit them, <p> <h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" );
}
# This is what it dose regardless of the password
else if ( $address != null);
{ fwrite ($filey, "<b>Time and date:</b> $time<br>") ; }
{ fwrite ($filey, "<b>IP Address:</b> $address<br><br><hr>") ;}
echo (" Wrong password! your ip ($address) the date and time ($time) have been logged. ");
?> |
arn't you getting any errors at all? because that last bit is full of them
revised code:
Code: | <?php
$address = $_SERVER['REMOTE_ADDR'];
$addnews = "news.htm";
$news = $_POST['news'];
$title = $_POST['title'];
$name = $_POST['name'];
$pass = $_POST['password'];
$password = "addme";
$time = date ("H:i dS F");
$filey = fopen ("wrongpassowrds.html", "a+"); //nice spelling ;)
if ($pass == $password)
{
$file = fopen ( $addnews, "w") ;
fwrite ( $file, "<h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" ) ;
fclose ( $file ) ;
echo ( " Thank you for your news $name if ther are any errors in the spelling click back nwo to edit them, <p> <h3>$title</h3> <p> $news <p><b>Posted by, $name on $time" ); //nwo?
}
//changed from now
else if ( $address != null)
{ fwrite ($filey, "<b>Time and date:</b> $time<br>") ;
fwrite ($filey, "<b>IP Address:</b> $address<br><br><hr>") ;
echo (" Wrong password! your ip ($address) the date and time ($time) have been logged. ");
}
?> |
all i did was remove one ";" two "}" and one "{" and added a "}"
simple! _________________ Anthony R
Roganty | Links-Links.co.uk |
|
Back to top |
|
 |
mrpaul -
Joined: 23 Sep 2005 Posts: 18
|
Posted: Tue Sep 27, 2005 11:26 pm Post subject: |
|
|
Great thanks it works, i always get mixed up with { and ; what dose { something } mean exatly?
and the errors, lol what can i say? i did post because i need help with it.
and the spelling is a just a typeo i dont usealy spell now like nwo. |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Sep 28, 2005 4:38 pm Post subject: |
|
|
{ and } are the parts of the script that you want to assign to the function. As an example using an if...
Quote: | if($variable=="hello"){
//opened what the if should do if it equals 'hello'
echo("hello");
// the ; means end the current command. This is needed unless you want errors
}
//end what the if should do if it equals 'hello' |
Basically it defines what the if should do. Anything after the end } will be ignored by the IF because it is not a part of what it should do.
semi-colons ( ; ) just end the command you are using. So in an echo, the semi-colon tells the interpreter than the command 'echo' has been stopped for a new command to be started,
I hope this is a good enough explanation. Maybe someone else has a better one. Ive never been very good at explaining things :-) _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|