Page 1 of 1

if / then code issue

Posted: Wed May 02, 2007 6:18 pm
by thefreebielife

Code: Select all

<?
$ostatus='1';
if($rid == '1') {
THEN code.
}
?>
i have that code plopped on my page with nothing else around it. its not working. should there be something before/after it?

Posted: Wed May 02, 2007 6:20 pm
by John Cartwright
What?

Posted: Wed May 02, 2007 6:22 pm
by thefreebielife
yeah i didnt explain that good haha

basically.. user signs up under a referral id. 1 in this case.

i want it to be so that the script automatically goes into the database and changes their offer status to complete.

should i post my whole code for the page?

Posted: Wed May 02, 2007 6:24 pm
by Weirdan
should i post my whole code for the page%AC
Sure.

Posted: Wed May 02, 2007 6:25 pm
by thefreebielife

Code: Select all

    <? 

$username = $_SESSION['username'];
$data = mysql_query("SELECT * FROM users WHERE username='$username'")
or die(mysql_error()); 
$info = mysql_fetch_array($data);
$giftid = $info['gid'];
$ostatus = $info['ostatus'];
$holdreason = $info['holdreason'];
$deadline = $info['deadline'];
$dead = $info['dead'];
$date = date("F j, Y");
$uid = $info['uId'];
$result = mysql_query("select * from users WHERE rid=$uid");
$count=mysql_num_rows($result);
$result2 = mysql_query("select * from users WHERE rid=$uid && ostatus=1");
$count2=mysql_num_rows($result2);
//show gift
$data3 = mysql_query("SELECT * FROM gifts WHERE gId='$giftid'")
or die(mysql_error()); 
$num = mysql_num_rows($data3);
if ($num == 0) {
$data10 = mysql_query("SELECT * FROM gifts");
$info = mysql_fetch_array($data10);
$giftid = $info['gId'];
$query="UPDATE users SET gid='$giftid' WHERE username='$username'";
mysql_query($query);
echo '<meta http-equiv="refresh" content="0;url=main.php">';
}
$data2 = mysql_query("SELECT * FROM gifts WHERE gId='$giftid'");
$r = mysql_fetch_array($data2);
$gname=$r["gName"];
$gref=$r["gRef"];
$gdescription=$r["gDescription"];
$gimage=$r["gImage"];
if ($date != $deadline && $dead == 0 or $date == $deadline && $count2 == $gref && $ostatus == 1)  { 
?>
          </p>
<div style="margin-left:200px "><font color="#0066FF">You Have Until <? echo "$deadline"; ?> To Complete The Requirements</font></div><Br>
<div id="mygift">
 <div class="myname"><? echo "$gname"; ?></div>
  <div align="center" style="color:red ">Item Requires <? echo "$gref"; ?> Referrals</div>
        <div class="myimage"><img src="<? echo "$gimage" ?>"/></div>
  <div class="myname"><? echo "$gdescription"; ?></div>
    <div align="right" style="text-decoration:none;"><a href="gifts.php">Change My Gift</a></div>
  </div><br>
  <div align="center">Your Referral Link &nbsp; <input name="referral" type="text" value="http://www.thefreebielife.com?r=<? echo "$uid"; ?>" size="50">
  </div>
  <bR>
<?
$ostatus='1';
if($rid == '1') {
THEN code.
}
?>

  <div class="border"></div><br>
  <div class="myname">My Status</div>
  <div align="center"><? if ($ostatus == 1) { ?> <font color="#009900"> You Have Completed An Offer!</font><? } else if ($ostatus == 0) { ?><font color="#000000"> You Have Not Completed An Offer</font><?  } else if ($ostatus == 2) { ?><font color="red"> You Have Been Placed On Hold <Br> <strong>Hold Reason: <? echo "$holdreason"; ?></strong></font><? } ?> 
    <br>
    <br>
  </div>
  
<?
$data4 = mysql_query("SELECT * FROM orders WHERE ousername='$username'");
$count4=mysql_num_rows($data4);
?>
<? if ($count2 < $gref) { ?>
<div align="center">You Have <? echo "$count2"; ?> Completed Referrals Out of <? echo "$gref"; ?> Needed</div>
<? } ?>
<? if ($count2 == $gref && $ostatus == 0) { echo "<div align=center><font color=red>You Are So Close.  All You Need To Do Is Complete An Offer!</font></div>"; } ?>
<? if ($count2 >= $gref && $ostatus == 1 && $count4 == 0) { echo "<div align=center><font color=#009900>Congrats!  You Are Ready To Order Your Free Gift. </font><font color=red><a href=\"order.php\"> Click To Order</a></font><Br>Make Sure Your Information Is Correct Before Ordering.  It Cannot Be Changed</div>"; } ?>
<? if ($count2 >= $gref && $ostatus == 1 && $count4 == 1) { echo "<div align=center><a href=\"order.php\"><font color=blue>Click To Check The Status Of Your Order</font></a></div>"; } ?>
<br>

	<table width="400" border="0" align="center" class="reftable">
  <tr>
    <td colspan="2" style="border-bottom:1px dashed orange "><div align="center">Your Referrals </div></td>
  </tr>
  <tr>
    <td width="50%" style="border-right: 1px dashed orange; border-bottom:1px dashed orange"><div align="center">Username</div></td>
	<td width="50%" style="border-bottom:1px dashed orange"><div align="center">Offer Status</div></td>
  </tr><? if ($count == 0) { ?>
    <tr>
    <td colspan="2"><div align="center"><font color="#FF0000">You Have No Referrals</font></div></td>
  </tr>
  <? } ?>

<?
//grab all the content
while($r=mysql_fetch_array($result))
{	
   $ruser=$r["username"];
   $roffer=$r["ostatus"];
   ?>
<tr>
    <td width="50%" style="color:#0099FF "><div align="center"><? echo "$ruser"; ?></div></td>
	<td width="50%"><div align="center"><? if ($roffer == 1) { echo "<font color=#009900>Offer Completed</font>"; } else if ($roffer == 0) { echo "<font color=red>Offer Not Completed</font>"; } else if ($roffer == 2) { echo "<font color=red>User Removed</font>"; }?> </div></td>
 </tr>  
   
 <? }  ?>
 </table>	<p>
<center><img src="images/offer.gif"></center>	<p>
		<? } else { echo "<div align=center><font color=red><h1>The Dead Line Has Past. <br> Your Account Is No Longer Active</h1></font></div>"; 
if ($dead == 0) {	
$query="UPDATE users SET dead=1 WHERE username='$username'";
mysql_query($query);
}
		} ?>

Posted: Thu May 03, 2007 2:19 am
by rebus
As far as i can see this code should return error Parse error: syntax error, unexpected T_STRING

Your checking for $rid but you dont set it anywhere. But then, perhaps you have register_globals set to ON.
And writing some code other then "THEN code" should do something.

And i suggest using <?php instead of <? for opening PHP blocks.

*shrug*

Posted: Thu May 03, 2007 5:30 pm
by thefreebielife
theres no error message... just the action doesnt work

Posted: Thu May 03, 2007 6:20 pm
by RobertGonzalez
This is almost certainly throwing a warning, but only if $rid is one (though actually PHP should be throwing a parse error because of the lack of the semi colon). You literally have THEN code in the conditional?

Code: Select all

<?
$ostatus='1';
if($rid == '1') {
THEN code.
}
?>

Posted: Thu May 03, 2007 6:22 pm
by thefreebielife
should i take the "then" part out?

Posted: Thu May 03, 2007 6:22 pm
by RobertGonzalez
Uh, yeah.

Also, where is $rid set?

Posted: Thu May 03, 2007 6:23 pm
by thefreebielife
in the users table

Posted: Thu May 03, 2007 6:25 pm
by RobertGonzalez
Where in your code is $rid given a value?

Posted: Thu May 03, 2007 6:28 pm
by thefreebielife
it works now ;)

that is the user they signed up under. it is given to them in registration