Jump to content

Recommended Posts

My paid system for a website I am working on, It is suppose list all the users in a table, and tell if the user has paid for not. If they have paid then it shows a link, to remove them from the paid table. If they have not paid (not in the paid table), then it is suppose to show a check box so I can check the users who have paid, and add them to the paid table.

 

Well the only part that works is show the users from the username table. It does show a checkbox or a link, but if I select one user that has paid, it show everyone on the list as paid, even when they are not in the paid table. It also adds a blank row in the table.

 

So can someone review my code and tell me what I could do better.

 

paid.php (shows list, and deter minds who has paid, and shows link or checkbox)

<?php
include ("../../style/include/session.php");
include ("../../style/include/cons/head_2.php");
if($session->isAdmin()){
print '<div class="box"><h2>Select Paid</h2>';
?>

<form action="pay_do.php" method="post">

<table width="63%" border="0">
  <tr>
    <td width="194"><strong>First Name </strong></td>
    <td width="261"><strong>Last Name </strong></td>
    <td width="273"><strong>Paid (username) </strong></td>
  </tr>
  <?
  
$qr=mysql_query("select * from users order by first");
$pt=mysql_query("select * from paid order by user");
while ($rs=mysql_fetch_assoc($qr)) {
       $pu=mysql_fetch_assoc($pt);
       $table = 'paid';
       $field = 'user';
       $compared = $pu['user'];
       $result = mysql_query("SELECT $field FROM $table WHERE $field = '$compared'");


?>
  <tr>
    <td><? echo $rs['first'];?></td>
    <td><? echo $rs['last'];?></td>
    <td>
<?
       if(mysql_num_rows($result)==0) {
             //"Not Paid ";			 
?>
<input type="checkbox" name="checkbox[]" onchange="if(this.checked) {  this.value='<? echo $rs['username'] ?>'; } else {  this.value=''; }" />
<?php
       } else {
             echo "Paid ";
       }
?>
(<? echo $rs['username']; ?>)
</td>
<?
}
?>
  </tr>
</table>



<br />
<input name="Submit" type="Submit" value="Mark Paid"  />
</form>

<?php
}else{
header("Location: ../../index.php");
}
print '</div>';
include ("../../style/include/cons/foot.php");
?>

 

paid_do.php (adds the user to the paid table)

<?php
include ("../../style/include/session.php");
include ("../../style/include/cons/head_2.php");
print '<div class="box">';
if($session->isAdmin()){
if(isset($_POST['Submit'])){
$boxes=$_POST['checkbox'];


$i=0;
while ($i<=count($boxes)) {
if($boxes[$i]!=='') {
mysql_query("insert into paid (user) values ('$boxes[$i]')");
}
$i++;
    }
echo "<h2>Processed</h2>";
echo "Selected users have been processed";
}else{
echo "<h2>Error!</h2>";
echo 'No data to process<br><a href="paid.php">Select Paid/Non-Paid</a>';
  }
}else{
header("Location: ../../index.php");
}
print '</div>';
include ("../../style/include/cons/foot.php");
?>

 

-Thanks Guys!

Link to comment
https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/
Share on other sites

this is my outcome

 

Array ( [checkbox] => Array ( [0] => admin ) [submit] => Mark Paid )

 

when I only select Admin

 

this is my outcome, when I select all.

Array ( [checkbox] => Array ( [0] => GoogleBot [1] => admin ) [submit] => Mark Paid )

Yes, but the system is not working, and I have gone over, and over the scripts.

 

When I select only one person as paid, it adds them only to the paid table. Then it says all the users have paid. Then it adds a blank row to the db, every time I select someone.

i have copied your code onto my server try changing the first bit after if($session->isAdmin()){ to this:

<?php
print_r($_POST);
print '<div class="box">';
if(isset($_POST['Submit'])){
$boxes=$_POST['checkbox'];
print_r($boxes);
foreach($boxes as &$value){
	if($value!=='') {
		$query="insert into paid (user) values ('$value')";
		echo $query.'<br />';
		mysql_query=($query);
	}
}
echo "<h2>Processed</h2>";
echo "Selected users have been processed";
}else{
echo "<h2>Error!</h2>";
echo 'No data to process<br><a href="paid.php">Select Paid/Non-Paid</a>';
}
print '</div>';
?>

that will remove the last empty line and should also show where your queries are going wrong

 

Scott.

I am not too sure what is wrong with this page, If I select one as paid, then view the page again it shows a link, like I want, but If I select another person, after already selecting one before (at different times) it shows checkboxes saying they are not in the paid table.

 

I think it is this page that has bad coding in it, will you view over it?

<?php
include ("../../style/include/session.php");
include ("../../style/include/cons/head_2.php");
if($session->isAdmin()){
print '<div class="box"><h2>Select Paid</h2>';
?>

<form action="pay_do.php" method="post">

<table width="63%" border="0">
  <tr>
    <td width="194"><strong>First Name </strong></td>
    <td width="261"><strong>Last Name </strong></td>
    <td width="273"><strong>Paid (username) </strong></td>
  </tr>
  <?
  
$qr=mysql_query("select * from users order by first");
$pt=mysql_query("select * from paid order by user");
while ($rs=mysql_fetch_assoc($qr)) {
       $pu=mysql_fetch_assoc($pt);
       $table = 'paid';
       $field = 'user';
       $compared = $pu['user'];
       $result = mysql_query("SELECT $field FROM $table WHERE $field = '$compared'");


?>
  <tr>
    <td><? echo $rs['first'];?></td>
    <td><? echo $rs['last'];?></td>
    <td>
<?
       if(mysql_num_rows($result)==0) {
             //"Not Paid ";
?>			 
<input type="checkbox" name="checkbox[]" value="<? echo $rs['username'] ?>" />
<?php
       } else {
echo '<a href="pay_dele.php?cmd=delete&user='.$rs['username'].'">Not Paid</a> '; 

       }
?>
(<? echo $rs['username']; ?>)
</td>
<?
}
?>
  </tr>
</table>



<br />
<input name="Submit" type="Submit" value="Mark Paid"  />
</form>

<?php
}else{
header("Location: ../../index.php");
}
print '</div>';
include ("../../style/include/cons/foot.php");
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.