Page 1 of 1
If Statement Problem
Posted: Tue Mar 22, 2011 2:53 pm
by micky007
Hi Guys,
Any help with my problem would be great, here is my code:
Code: Select all
<?
if($affstatus == "Pending"){
$protext="Your application to run this campaign is under review, please allow 48hrs to review your application.";
} elseif($affstatus == "Declined"){
$protext="Your application to run this campaign has been Declined. Please speak with your affiliate manager.";
} elseif($affstatus == "Approved"){
//display banners etc..
$display=eval('echo "'.$string.'";');
$protext="<table width='741' border='0' cellpadding='2' cellspacing='2'>
<tr>
<td bgcolor='#FFFFFF'><strong>Banner ID:</strong> <? echo $bannerid; ?><br />
<img src='<? echo $bannerurl; ?>' /></td>
</tr>
<tr>
<td bgcolor='#FFFFFF'><textarea name='BannerCode' id='BannerCode' cols='60' rows='5'><? echo $display; ?></textarea></td>
</tr>
</table>";
}
echo $protext;
?>
The output is fine if $affstatus is Pending. If value is Approved then nothing is displayed and if the value is Declined then it outputs the text but it outputs it 3 times for some reason.
Again any help on this would be fantastic.
Thank you very much guys
Re: If Statement Problem
Posted: Tue Mar 22, 2011 2:59 pm
by Jonah Bron
Code: Select all
$display=eval('echo "'.$string.'";');
What's that supposed to do? Lets try this:
Code: Select all
<?php
if($affstatus == "Pending"){
$protext="Your application to run this campaign is under review, please allow 48hrs to review your application.";
} elseif($affstatus == "Declined"){
$protext="Your application to run this campaign has been Declined. Please speak with your affiliate manager.";
} elseif($affstatus == "Approved"){
//display banners etc..
$protext="<table width='741' border='0' cellpadding='2' cellspacing='2'>
<tr>
<td bgcolor='#FFFFFF'><strong>Banner ID:</strong> $bannerid<br />
<img src='<?$bannerurl' /></td>
</tr>
<tr>
<td bgcolor='#FFFFFF'><textarea name='BannerCode' id='BannerCode' cols='60' rows='5'>$string</textarea></td>
</tr>
</table>";
}
echo $protext;
?>
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:07 pm
by angelicodin
What about making your if statements === for an absolute equals?
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:10 pm
by micky007
Hi,
That code needs to be in there as the value of one of the rows in the database has PHP variable tags in it which need to be replaced. It works with this code below.
Code: Select all
<?
//GET BANNERS FOR PROGRAM
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");
$query="SELECT * FROM programbanners WHERE ProgramID ='$programid'";
$result=mysql_query($query);
$num=mysql_numrows($result) or die(mysql_error());
$i=0;
while ($i < $num) {
$bannerid=mysql_result($result,$i,"BannerID");
$type=mysql_result($result,$i,"Type");
$code=mysql_result($result,$i,"Code");
$bannerurl=mysql_result($result,$i,"BannerURL");
$string = $code;
$string = addslashes($string);
?>
Also the code you told me try doesnt look any different except the line you asked about being removed.
Thanks
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:12 pm
by micky007
angelicodin wrote:What about making your if statements === for an absolute equals?
I've tried, still the same problem
Thanks
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:25 pm
by Jonah Bron
Echo the value of $affstatus before the if statement, and confirm that the value you're expecting is what you're receiving.
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:26 pm
by angelicodin
Hmmm, I'll looked at it in my own php editor and it looks correct for the most part (outside of stylizing for coding ;p), so I have no idea why it would be displaying three times if it's anything other than pending. Can you try changing it, so it's IF(){} and for the elseif make them if(){} and see where the code is going weird. Also I would check to see what the actual value is for the $affstatus variable to make sure it's not being changed at some point (who knows). But the only think I can think of why it would be displaying it 3times is, a loop or the value for the conditional is not proper for some reason.
(EDIT: LOL was thinking the same thing)
Re: If Statement Problem
Posted: Tue Mar 22, 2011 3:34 pm
by micky007
Hi Guys,
Thanks for getting back to me, yea i always echo the value of a variable im having a problem with and everything is fine which is why i dont understand why its not working right. Do you mind if i provide you with the php file you can take a look at it for me please?
Also pm me an email address in order to send you the file if your willing to take a look for me.
Thanks for your comments so far guys
Thank you.
Re: If Statement Problem
Posted: Tue Mar 22, 2011 4:06 pm
by Jonah Bron
Can you just post all the code here?