Lamez Posted February 4, 2008 Share Posted February 4, 2008 I have a paid system for my website (I mean I want to make one) How would I write my if statement I have this so far, but I do not think it is correct: <?php include ("style/include/session.php"); $q = "Select count(*) as row_count from `paid`"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if ($row['paid'] == ('yes')){ echo "Paid"; }else{ echo "Not Paid"; ?> How do I make it call it for each user individually this is what I use to define the user: $session->username any help? Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/ Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 if the username and paid are coming from the same table, just do $q = "Select count(*) as row_count from `paid` where username='$_SESSION[username]'"; otherwise you need some variable in the table to tell you what user it is for, such as a userid or username, and do what I just wrote. Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457231 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 well I got to thinking, it might to make a table, with just the username then do a if exist statement, so if the username exist, it outputs "you have paid" otherwise "you need to pay" how would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457234 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 would this work? <?php include ("style/include/session.php"); $q = "SELECT user FROM `paid` "; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if (function_exists($session->username){ echo "you have paid"; }else{ echo "you need to pay"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457237 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 you should really have a table with two fields, username and paid, but if you are only creating the table for the username is they have already paid then you do this: $q = mysql_query("Select * from tablename where username='$_SESSION[username]'"); $numberrows=mysql_num_rows($q); if($numberrows=='0') { ...whatever you want if the user hasn't paid; } else { whatever you want if the user has paid; } Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457240 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 well I get this error now: what does it mean? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mounted-storage/home48c/sub007/sc33591-LWQU/lamezz.info/test.php on line 4 Please Pay here is my code <?php include ("style/include/session.php"); $q = mysql_query("Select * from tablename where user='$session->username'"); if(mysql_num_rows($q) ==0){ echo "Please Pay"; }else{ echo "You Paid!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457251 Share on other sites More sharing options...
haku Posted February 4, 2008 Share Posted February 4, 2008 There is an error in your my_sql syntax, so it is returning a value that has no rows in it, which means that mysql_num_rows() is failing. Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457253 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 is the name of your table tablename? i was using that as generic Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457254 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 oh yea I forgot Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457260 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 ok how would I make a check list, where I can check off the user who has paid? I have been trying to make this part for the last 45mins now. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457273 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 here is what I have so far: <?php $q = "SELECT user,first,last " ."FROM ".TBL_USERS.""; $user = mysql_result($result,$i,"user"); $fname = mysql_result($result,$i,"first"); $lname = mysql_result($result,$i,"last"); ?> <form name="form1" method="post" action=""> <table width="200" border="0"> <tr> <td width="103">First Name </td> <td width="87">Paid</td> </tr> <tr> <td><?php echo "$fname $lname"; ?></td> <td><label> <input type="<?php echo "$user"; ?>" name="checkbox" value="<?php echo "$user"; ?>"> </label></td> </tr> </table> <br> <label> <input type="submit" name="Submit" value="Submit"> </label> </form> <?php include ("../../style/include/session.php"); include ("../../style/include/cons/head_2.php"); print '<div class="box"><h2>Control Panel</h2>'; if($session->isAdmin()){ ?> <?php }else{ header("Location: ../../index.php"); } print '</div>'; include ("../../style/include/cons/foot.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457278 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 what exactly do you mean? if the user has paid, you want the box to be checked, or else not? Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457279 Share on other sites More sharing options...
Lamez Posted February 4, 2008 Author Share Posted February 4, 2008 no I want to be able to put a check be side their name, and then click submit, then it adds them to the paid table. Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457280 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 use AIM mfrederick20 Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457283 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 <table> <td> <form action="pay_do.php" method="post"> <? $qr=mysql_query("select * from users order by first"); while ($rs=mysql_fetch_assoc($qr)) { ?> <input type="checkbox" name="<?=$rs['first']?>" /><? echo $rs['first'];?><br /> <? } ?><input type="submit" value="Mark Paid" /> </form> </td></table> Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457288 Share on other sites More sharing options...
mikefrederick Posted February 4, 2008 Share Posted February 4, 2008 this is on the right track but I can't do too much more for free, easy stuff though. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table> <td> <form action="pay_do.php" method="post"> <? $qr=mysql_query("select * from users order by first"); $rs=mysql_fetch_assoc($qr); $num=mysql_num_rows($qr); $x=0; while ($x<$num) { ?> <input type="checkbox" name="a<?=$x?>" value="<?=$rs['first']?>"/><? echo $rs['first'];?><br /><br /> <? $x++; } ?><input type="submit" value="Mark Paid" /> </form> </td></table> </body> </html> pay_do.php: <? extract($_POST); $qr=mysql_query("select * from users order by first"); $rs=mysql_fetch_assoc($qr); $num=mysql_num_rows($qr); $x=0; while ($x<$num) { $qr2=mysql_query("select * from paid where user=(get stuff from post)"); $numrows=mysql_num_rows($qr2); if($numrows=='0') { mysql_query("insert into paid (user) values ($(stuff from post))"); } $x++; } Header("Location:wherever.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/#findComment-457294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.