Jump to content

MySQL w/ PHP if statment


Lamez

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/89295-mysql-w-php-if-statment/
Share on other sites

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.

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";
?>

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; }

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!";
}
?>

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");
?>

<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>

 

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");

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.