PDA

View Full Version : More if/else probs


zoobie
07-18-2003, 05:51 AM
I think somethings wrong with the code below as it also won't echo out an error message...All I get is a blank white page...Will the rest work ok? Thanks

<?php

$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$receiver_email = $_POST['receiver_email'];

$display = "<html><body><div align='center'><form name='fred' action='mail.php' method='post'><button onclick='this.fred.submit();'>SEND IT!</button></form></div></body></html>";

$error = "<html><body bgcolor='red'><div align='center'>ERROR</div></body></html>";


if ('Completed' == $payment_status){
if ($receiver_email == 'zoob@pop3.com') {
if ('0.02' == $payment_gross) {
echo "$display";
}
}
}

else{
echo "$error";
}

?>

raf
07-18-2003, 08:07 AM
Maybe it can be shortened to

<?php
echo "<html><body><div align=\"center\">";
if ($_POST['payment_status'] == 'Completed') AND ($_POST['receiver_email'] == 'zoob@pop3.com') AND $_POST['payment_gross'] == '0.02') {
echo "<form name=\"fred\" action=\"mail.php\" method=\"post\"><input type=\"submit\" value=\"SEND IT\" name=\"send\"></form>";
}
else{
echo "ERROR";
}
echo "</div></body></html>";
?>
I'd also recommend using a regular submitbutton instead of that javascript. And having that red background i kinda over the top, no ?

zoobie
07-18-2003, 08:24 AM
Actually, mine was working but something
got stuck...heh heh.
Nope...red isn't 'over the top' when they're
trying to cheat Paypal and me by not paying. :cool:
Thx

raf
07-18-2003, 12:13 PM
You don't get it. You say 'it's working', sure, but if if ('Completed' == $payment_status) is true
and one of the followingcomparisons
( if ($receiver_email == 'zoob@pop3.com')
if ('0.02' == $payment_gross) )
is false, then you will see nothing, cause the else clause is only ran if
if ('Completed' == $payment_status)
is false.

So if you only wan't to display the "send it" button if the firsts three comparisons are true, then you eiter
- need to suply additional else clauses for each nested if-then control, or
- need to use one 'if' check on three conditions (like my code). And that would be smarter, unless you wan't to display detailed errormessages --> echo or highlight the invalid values. Then you can use code like the one i posted in your previous thread

So indeed, you're code doesn't contain syntax errors or so, but it's incomplete (since not all possibilitys are covered), to long, not XHTML compliant and contains unnescecary javascript.

zoobie
07-18-2003, 06:33 PM
Ahhhhhh......I get it now.
Yes...I agree the javascript should go...
How would I write it for individual errors and if all passed echo $display?
Thanks :o

ConfusedOfLife
07-18-2003, 11:10 PM
if ('Completed' == $payment_status)
{
if ($receiver_email == 'zoob@pop3.com')
{
if ('0.02' == $payment_gross)
{
echo "$display";
}
else
echo $error3;
}
else
echo $error2;
}
else
echo $error1;


:D

zoobie
07-18-2003, 11:35 PM
Hey...It's deja vu all over again...heh heh.
I just don't quite understand why it doesn't need closing curly brackets
else {
echo $error1
}


Guess PHP doesn't need 'em...Hell, I dunno. :D

PS - I just noticed the rotating ad at the top of this page offering Paypal security for only $14.95...That's exactly what this script I'm working on is all about...heh heh. Tell ya what...You can have this one for only $3.95...Send before midnight tomorrow...ha ha! :cool:

ConfusedOfLife
07-19-2003, 11:48 AM
Hey, I'm not openning any brackets for my elses, so, I don't close anything for them! I don't need to open any brackets for my else clauses, because all my nested ifs have their brackets (so, it doesn't confused an else for a wrong if) and each else only contains one directive, so, what's wrong with it?! After you asked it twice (once in here and once ...) I checked it again and works! ;)

zoobie
07-19-2003, 05:39 PM
Allllllllrighty then...I didn't have the chance to test it yet...just wondered...Yes...sometimes I post in that "other" place because they may have a different insight or I need the answer quickly. Then, there's the "other other" place and the "other other other" place, too..:D

Sure I can't interest you in this script you've worked on? Only $3.95 'till midnight tomorrow...heh. :p

See ya 'round...Thanks again :thumbsup:

ConfusedOfLife
07-20-2003, 09:33 PM
Originally posted by zoobie
Allllllllrighty then...I didn't have the chance to test it yet...just wondered...Yes...sometimes I post in that "other" place because they may have a different insight or I need the answer quickly. Then, there's the "other other" place and the "other other other" place, too..:D

Sure I can't interest you in this script you've worked on? Only $3.95 'till midnight tomorrow...heh. :p

See ya 'round...Thanks again :thumbsup:

I do it too dear! I think it's very normal, you see new ppl, new ideas and ... But then I don't have that other other other place, not even a other other place! As for as interesting me in anything, lemme tell ya that I have no money to spend nowadays! I'm planning for something BIG, and I have to keep my money! And I don't have that much, you know? :(