Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

problem with PHP 'IF' statement.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

problem with PHP 'IF' statement.

Postby TrickyRic » Mon Mar 03, 2003 6:42 am

hi everybody, im new to PHP and although it seems like a fairlly simple language to learn, im having problems with the 'IF' statement. im guessing its something simple but please remember ive only been using PHP for 2 or 3 weeks.
ok here goes...
im creating a password system for a site im developing, you can see the problem by attempting to download floorman from http://members.lycos.co.uk/phppage (temporary site location). anyway, when you press the download link after entering a code (valid or invalid) i get a parse error which points to the start of my 'IF' statement.
before i post the code, heres what it should do, the code is placed in the centre of the page so all other parts of the page are in html (the menu and header etc...) anyway, the code should look to see if the password entered is equal to the correct password, if it is, a table is made and a download link appears. otherwise a different table is made and no download link appears. ok... heres the code...

<?php
$typed = "\t$_POST[attempt]\n";
$correct = "j23n377CC96q693329b8sClH";
if($typed = $correct);
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Floorman 2003</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Thank you.<br>
You may now download your chosen product by clicking <a href="j23n377CC96q693329b8sClH/FM2003.zip" class="linksheet">Here</a>.</td>
</tr>
</table>
else;
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Error</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Sorry.<br>
The code you entered was invalid. Please check you have typed a valid
code and that the code matches the chosen product.</td>
</tr>
</table>
endif;
?>

...im making the table through HTML and im guessing thats the problem? if so, how can i include HTML inside a PHP script?

thanks, i really appreciate any help you can offer. by the way, the password is supposed to be bought through a paypal account so write it down somewhere so you can download a free copy when its all working :)
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada

Re: problem with PHP 'IF' statement.

Postby WiZARD » Mon Mar 03, 2003 7:12 am

Hi!
If you see at youre code carefuly you see this:
Code: Select all
$typed = "\t$_POST[attempt]\n";
$correct = "j23n377CC96q693329b8sClH";
if($typed = $correct);

As i know \n it's return!
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

reply

Postby Skeletor » Mon Mar 03, 2003 7:17 am

Try something like this perhaps. Also, could probably use this statement for $typed, but I don't think it will matter.
$typed = $_POST['attempt'];
You must exit php every time you place regular html in your code. Either exit or just put your html in a print statement.
such as: print('<table width="475" border="0" cellspacing="0" cellpadding="0">');

<?php
$typed = "\t$_POST['attempt']\n";
$correct = "j23n377CC96q693329b8sClH";
if($typed == $correct) {
?>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Floorman 2003</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Thank you.<br>
You may now download your chosen product by clicking <a href="j23n377CC96q693329b8sClH/FM2003.zip" class="linksheet">Here</a>.</td>
</tr>
</table>
<?php
} else {
?>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Error</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Sorry.<br>
The code you entered was invalid. Please check you have typed a valid
code and that the code matches the chosen product.</td>
</tr>
</table>
<?php
}
?>
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

Postby Redcircle » Mon Mar 03, 2003 7:53 am

if statements use == not =
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

thanks!

Postby TrickyRic » Mon Mar 03, 2003 2:47 pm

thanks everyone, i wasnt even sure if i'd get 1 reply yet alone 3, great forum :)

lots of ideas, ill try them all out and get back to you, and thanks for the info on /n i wasnt sure why it was there but it seemed to work for sending mail so i just re-used it :)

anyway, ill let you know if i get it working.
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada

lol am i stupid?

Postby TrickyRic » Mon Mar 03, 2003 4:43 pm

lol, in continuation to the bit about /n ....i cant believe i could be so stupid, ive not understood why its there since i started PHP an now ive just realised its exactly the same as C++ lol, sorry its been a long 2 weeks. (well thats my excuse anyway).

getting back to the initial topic... ive made a few changes and im now hoping it works, however my system isnt set as a web server because IIS isnt supported by XP Home and i havnt got time to format and install 2000 so i cant preview PHP scripts :( anyway, as youve probably guessed by the site address, im using lycos to test all php at the moment and so all i need to do is upload the new page and let you know if it works, its just a pitty ive left my firewall on and it doesnt like ftp addresses very much (well it doesnt like them at all infact) anyway i cant disable it because i need to reconnect afterwards and its 00.40 at the moment so i dont think my family would be too happy waking up to the sound of my modem in the middle of the night.
anyway, basically youll have to wait til tomorow to see if it works, just like me :( but heres the new code in advance just incase it does :)
thanks again.

<?php
$typed = "\t$_POST[attempt]\n";
$correct = "j23n377CC96q693329b8sClH";
if($typed == $correct);
{
?>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Floorman 2003</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Thank you.<br>
You may now download your chosen product by clicking <a href="j23n377CC96q693329b8sClH/FM2003.zip" class="linksheet">Here</a>.</td>
</tr>
</table>
<?php
}
else;
{
?>
<table width="475" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td bgcolor="#000099" colspan="3">
<div align="center"><font face="Courier New" size="2">Error</font></div>
</td>
</tr>
<tr align="left">
<td colspan="3" valign="top">Sorry.<br>
The code you entered was invalid. Please check you have typed a valid
code and that the code matches the chosen product.</td>
</tr>
</table>
<?php
}
endif;
?>
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada

Postby Skeletor » Tue Mar 04, 2003 4:51 am

if your last code doesn't work, try taking the simicolons off the if and else statements, and take out the endif.

It may be a legal way to do an if statement, I just never seen it done that way within php.

good luck.
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

almost...

Postby TrickyRic » Tue Mar 04, 2003 5:31 am

well it didnt work but your idea about the ; and endif parts seems to have got us closer. it now displays the table however it doesnt seem to like the code, lol, it always displays the error page to show the code was invalid even if i copy and paste straight from the PHP code.
thanks anyway, ill try and find why its not liking my code now...
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada

Postby Skeletor » Tue Mar 04, 2003 6:09 am

are you entering in the string of "j23n377CC96q693329b8sClH" into the attempt variable from another form? If your entering in that string and passing it to this script, try changing your $typed to this:

$typed = $_POST['attempt'];

This would put the value of the post variable "attempt" into $typed. Something else to try would be enclosing 'attempt' in single quotes in the example you already have.
$typed = "\t$_POST['attempt']\n";

not sure if these will fix it, but is worth a try :]

good luck.
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

solved!

Postby TrickyRic » Tue Mar 04, 2003 6:50 am

wow, you lot know your stuff.
thanks, that idea solved it, i dont know where id be if i hadnt found this forum but i doubt if it would be working yet. thanks to everyone who helped and im sure ill be back with more problems soon, lol.
ill add a link back to this site too, i was originally intending to add pay-per-click links but ill make an exception here as the site wouldnt be working if it wasnt for these forums :)
well anyway, although its still on a temporary host, everything is downloadable so feel free to use that code for a free download.
hmm, just need to add a few more pages, find a host, set up a paypal button and then ill be ready to buy my domain so thanks again to everyone here.
User avatar
TrickyRic
New php-forum User
New php-forum User
 
Posts: 50
Joined: Mon Mar 03, 2003 6:28 am
Location: Toronto, Canada


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron