Jump to content

[SOLVED] unban script


lewis987

Recommended Posts

ok i have a script that if the banend <= than the current date then unban them but my problem is that it doesnt want to do it, any ideas?

 

$datetime=date("y-m-d H:i:s");
$tblbanned=$prefix."banned";

if($datetime >= $rows['banend']){
mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE username='$user'");
}

Link to comment
https://forums.phpfreaks.com/topic/56258-solved-unban-script/
Share on other sites

if($datetime >= $rows['banend']){

mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE username='$user'");

}

 

 

I think your problem may be the highlighted typo.  Unless I'm misunderstanding your structure, I do believe that should be 'banned' and not 'banend' :)

 

Good luck!

 

EDIT: oh wow, dee dee dee moment.  I just reread this more carefully and realized you DID mean banend - as in Ban End.  Apologies!

 

I think the post below may be more on track.

 

Good luck!

 

Link to comment
https://forums.phpfreaks.com/topic/56258-solved-unban-script/#findComment-277895
Share on other sites

Change:
[code]
if($datetime >= $rows['banend']){
mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE username='$user'");
}

to:

if($datetime >= $rows['banend']){
    $query = "UPDATE $tblbanned SET `banned` = '0' WHERE username='$user'";
    echo $query;
    // $result = mysql_query($query);
}

 

Does the query look like what you expected? Post the querystring here.[/code]

Link to comment
https://forums.phpfreaks.com/topic/56258-solved-unban-script/#findComment-278386
Share on other sites

Andy - if there are 1000 users banned on one day then that loop will not unban them all (I say that as most pages are limited to 50 queries - which is why it would be more beneficial to just update those records where the banned date has expired as a block rather than individually).

 

Lewis - what version of mysql are you running?

 

<?php
mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE `banneddate' < DATE_SUB(NOW(), 60 DAY)");
?>

 

That query should unban everyone who's ban date was more than 60 days ago. It does require that you store a banned date in the fields that is of a datetime type ('YYYY-MM-DD HH:mm:ss') if you have that then all should be fine.

Link to comment
https://forums.phpfreaks.com/topic/56258-solved-unban-script/#findComment-278475
Share on other sites

got it working! :D

 

the code had to be:

 

  $banned = mysql_query("SELECT * FROM $tblbanned WHERE `username`='$user'");
  $rows=mysql_fetch_array($banned);
if($datetime > $rows['banend']){
mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE `username`='$user'");
}

 

rather than:

 

  $banned = mysql_query("SELECT * FROM $tblbanned WHERE `username`='$user'");
  $rows=mysql_fetch_array($banned);
if($datetime >= $rows['banend']){
mysql_query("UPDATE $tblbanned SET `banned` = '0' WHERE `username`='$user'");
}

Link to comment
https://forums.phpfreaks.com/topic/56258-solved-unban-script/#findComment-278598
Share on other sites

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.