PHP help!

  • lagislabonita
  • Novice
  • Novice
  • lagislabonita
  • Posts: 20

Post 3+ Months Ago

Hi there, I'm recently new to PHP and I need help on some function/if else statements.
I'm doing a function that will see if a member is banned from the shoutbox then make it impossible for the member to post a shout but iv'e been unsuccessfull. Can someone tell me why this isn't working?


This is the function:
Code: [ Select ]
function ShoutboxBan($checkshban) {
global $dbprefix;
$query = "SELECT * FROM {$dbprefix}members WHERE shban = '$checkshban' AND disable = '0'";
$result = mysql_query($query)
     or die(mysql_error());
$row = mysql_fetch_array($result);
@extract($row);
 
if($checkshban != 0) {
return false;
}
else {
return true;
}
 
 
}
  1. function ShoutboxBan($checkshban) {
  2. global $dbprefix;
  3. $query = "SELECT * FROM {$dbprefix}members WHERE shban = '$checkshban' AND disable = '0'";
  4. $result = mysql_query($query)
  5.      or die(mysql_error());
  6. $row = mysql_fetch_array($result);
  7. @extract($row);
  8.  
  9. if($checkshban != 0) {
  10. return false;
  11. }
  12. else {
  13. return true;
  14. }
  15.  
  16.  
  17. }


This is the php code to make sure the user is not banned from the shoutbox
Code: [ Select ]
 
<?php
 
if(checkLogin(MEMBER_NAME, MEMBER_PASS) AND checkRank(MEMBER_RANK, $pid) AND ShoutboxBan($checkshban)) {
*php info here*
 
}
else {
echo "
<table align='center' border='0' cellspacing='0' cellpadding='0' width='400'>
<tr>
<td class='main' align='center'>You are either banned from the shoutbox or your rank is not high enough to view this page</td>
</tr>
</table>
";
}
 
?>
 
  1.  
  2. <?php
  3.  
  4. if(checkLogin(MEMBER_NAME, MEMBER_PASS) AND checkRank(MEMBER_RANK, $pid) AND ShoutboxBan($checkshban)) {
  5. *php info here*
  6.  
  7. }
  8. else {
  9. echo "
  10. <table align='center' border='0' cellspacing='0' cellpadding='0' width='400'>
  11. <tr>
  12. <td class='main' align='center'>You are either banned from the shoutbox or your rank is not high enough to view this page</td>
  13. </tr>
  14. </table>
  15. ";
  16. }
  17.  
  18. ?>
  19.  


Basically it is not working weather i change the value from 1 to 0 vice versa in the database
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

So, the column you are trying to retrieve is named 'checkshban' correct?
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

@lagislabonita

what's the output you are getting?
or else show us the whole script?!

cos syntax is correct, don't know abt logic
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

Just pic a way you want to handle your logic and you should be good as darklord said.

Code: [ Select ]

//declare function people with 0 will not be allowed access
function ShoutboxBan($checkshban) {
//shouldn't need to query here , you're not using it for anything in the function

//swap your true and false around cause you want the function to be true if shoutbox is allowed
// anything could cause your function to return false and allow access
if($checkshban != 0) {
return true;
}
else {
return false;
}

}


/*
maybe something like this
query your table get your row
$query = "SELECT * FROM {$dbprefix}members WHERE userid = '$userid' AND active = '1'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){

$yes_or_no = $row['shban'];

}
*/

$yes_or_no = 0; //for testing purposes, toggle on or off this user will not be allowed
$x = ShoutboxBan($yes_or_no);

// there are many ways to do your if statement here. see post
if($x) {
// if $x is true allow access for people in the db with shban set to anything above 0
echo "*php info here* Here is what $x looks like";

}
else {
// if user shban is equal to 0 they're not allowed
echo "
<table align='center' border='0' cellspacing='0' cellpadding='0' width='400'>
<tr>
<td class='main' align='center'>You are either banned from the shoutbox or your rank is not high enough to view this page.</td>
</tr>
</table>
";
}
  1. //declare function people with 0 will not be allowed access
  2. function ShoutboxBan($checkshban) {
  3. //shouldn't need to query here , you're not using it for anything in the function
  4. //swap your true and false around cause you want the function to be true if shoutbox is allowed
  5. // anything could cause your function to return false and allow access
  6. if($checkshban != 0) {
  7. return true;
  8. }
  9. else {
  10. return false;
  11. }
  12. }
  13. /*
  14. maybe something like this
  15. query your table get your row
  16. $query = "SELECT * FROM {$dbprefix}members WHERE userid = '$userid' AND active = '1'";
  17. $result = mysql_query($query);
  18. while($row = mysql_fetch_array($result)){
  19. $yes_or_no = $row['shban'];
  20. }
  21. */
  22. $yes_or_no = 0; //for testing purposes, toggle on or off this user will not be allowed
  23. $x = ShoutboxBan($yes_or_no);
  24. // there are many ways to do your if statement here. see post
  25. if($x) {
  26. // if $x is true allow access for people in the db with shban set to anything above 0
  27. echo "*php info here* Here is what $x looks like";
  28. }
  29. else {
  30. // if user shban is equal to 0 they're not allowed
  31. echo "
  32. <table align='center' border='0' cellspacing='0' cellpadding='0' width='400'>
  33. <tr>
  34. <td class='main' align='center'>You are either banned from the shoutbox or your rank is not high enough to view this page.</td>
  35. </tr>
  36. </table>
  37. ";
  38. }


You may want to get the values from your three functions checkLogin, checkRank, and ShoutboxBan much like the example with $yes_or_no and then use those to build your 'if statement'.

Code: [ Select ]

if ($x == 1 AND $y == 1 AND $z == 1) {
//access granted to shoutbox
} else {
// deny access to shoutbox
}
  1. if ($x == 1 AND $y == 1 AND $z == 1) {
  2. //access granted to shoutbox
  3. } else {
  4. // deny access to shoutbox
  5. }


So it really just looks like alot of logic work to do and that's mostly up to you and what you're comfortable with.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 90 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.