• PHP and MySQL trying to make a script for time limited ban

    Ganesh Member

    PHP and MySQL trying to make a script for time limited ban

    I’ve made a database with the option to kick someone for a certain amount of time but seems like I’m doing something wrong somewhere can anybody please assist

    <? include "./emoticon_replace1.php"; if ($_POST["DeletePost"]) { $id = $_POST["id"]; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add)) { $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } else { echo "Error: Not a valid IP: ".$IP_To_Add; } } if ($_POST["purge"]) { $query = "TRUNCATE TABLE ".$dbTable; mysql_query($query); echo "StringyChat purged"; } if(!$_POST["update"] || !$_POST["StringyChat_name"] || !$_POST["StringyChat_message"]) { } else { $id = $_POST["id"]; $name = $_POST["StringyChat_name"]; $message = $_POST["StringyChat_message"]; include("emoticon_replace.php"); $query = "UPDATE ".$dbTable." SET StringyChat_name='$name', StringyChat_message='$message' WHERE id='".$id."'"; $result = mysql_query($query, $db) or die("Invalid query: " . mysql_error()); } if ($_POST["EditPost"]) { $id = $_POST["id"]; $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'", $db); $myrow = mysql_fetch_array($result); ?>
    if ($_POST["1h"]) {
        $mxitid1= $_POST["1h"];
        if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
        {
          $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
          $result1 = mysql_query($sq1l);
        } else {
          echo "Error: Cannot Kick: ".$IP_To_Add;
        }
      }
    function checkban($mxitid)
        {
            // querys database
            $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db);
            $get = mysql_num_rows($q);
            // if found
            if ($get == "1")
                { 
                    // deny user access
                    $r=mysql_fetch_array($q);
                    die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at .");
                }
        }
    

    What I’m trying to do is to ban the person for 1 day. And by banning the person I want them to be blocked from my Index page from submitting a form (sending a message) which is stored as tik.php on my index page

  • SapnaVishwas Member

    Try to use mysqli instead, mysql has been deprecated.
    as for the problem :

    $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db);
    

    not sure if a php function withing a statement works …

    rather try :

    $now=now()l
    $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > '$now' AND mxit_id = '$mxitid'",$db); 
    
  • Ganesh Member

    How I do mysqli:

    $mysqli = new mysqli("localhost", "databaseuser", "databasepass", "database");   //<<< FIX THIS TO YOUR INFO
    $sql = "SELECT * FROM databasetablehere WHERE id='$recordid'";
    if(!$result = $mysqli->query($sql)){
        die('There was an error running the query [' . $mysqli->error . ']');
    }
    else
    {
    while($row = $result->fetch_assoc()){
    $user_id = $row['user_id'];
    $anothercolumn = $row['column2'];
    
    }
    }
    $mysqli->close();
    

    Easy stuff, get the info, do your if statement logic to check returned vars

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish