Lamez Posted February 8, 2008 Share Posted February 8, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/ Share on other sites More sharing options...
ratcateme Posted February 8, 2008 Share Posted February 8, 2008 try changing onchange="if(this.checked) { this.value='<? echo $rs['username'] ?>'; } else { this.value=''; }" to: value="<? echo $rs['username'] ?>" to make sure your javascript isn't the problem Scott. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-461583 Share on other sites More sharing options...
Lamez Posted February 8, 2008 Author Share Posted February 8, 2008 If I select one person, it still says everyone has paid even when they are not in the paid table. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-461707 Share on other sites More sharing options...
Lamez Posted February 8, 2008 Author Share Posted February 8, 2008 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462164 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 ??? Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462319 Share on other sites More sharing options...
ratcateme Posted February 9, 2008 Share Posted February 9, 2008 add this to the top of your script to see what input you are getting print_r($_POST); post any odd results. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462326 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462693 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 [pre]What is this[/pre] just lookin at the new update. Preformatted Text Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462694 Share on other sites More sharing options...
ratcateme Posted February 9, 2008 Share Posted February 9, 2008 this is my outcome, when I select all. Array ( [checkbox] => Array ( [0] => GoogleBot [1] => admin ) [submit] => Mark Paid ) is this what you expected ???????? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462750 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462756 Share on other sites More sharing options...
ratcateme Posted February 9, 2008 Share Posted February 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462831 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 wow thank you very very much! I am very thankful to have someone like you helping me! Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462846 Share on other sites More sharing options...
ratcateme Posted February 9, 2008 Share Posted February 9, 2008 so it is solved ??? remember to press "Topic solved" Scott. Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462856 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 I would, but is it not down there as usual Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462861 Share on other sites More sharing options...
Lamez Posted February 9, 2008 Author Share Posted February 9, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90013-paid-system-is-not-working-properly/#findComment-462872 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.