Jump to content

Lookup data and modifying data into database help needed


Go to solution Solved by cobusbo,

Recommended Posts

Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.

 

My Http link look something like 

 

and my ban.php page where I want to lookup the 159 part and do the banning etc looks like

<?
include("admin_code_header.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"];
    
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
  }
$result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db);

  while ($myrow = mysql_fetch_array($result)) {
    $msg = $myrow["StringyChat_message"];
$idm = $myrow["id"];



?>
<html>
<form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input name="DeletePost" type="submit" id="DeletePost" value="Delete">

<input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
    </form>
</html>
<?
}
?>

 

Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.

 

My Http link look something like 

 

and my ban.php page where I want to lookup the 159 part and do the banning etc looks like

<?
include("admin_code_header.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"];
    
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
  }
$result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db);

  while ($myrow = mysql_fetch_array($result)) {
    $msg = $myrow["StringyChat_message"];
$idm = $myrow["id"];



?>
<html>
<form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input name="DeletePost" type="submit" id="DeletePost" value="Delete">

<input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
    </form>
</html>
<?
}
?>

Ok so I spend some more time with the script and made a few more changes. The options display now but nothing happens when I try to execute them.

First of all I added the ip to my URL as well

 and made a few changes in my ban.php file like the $_POST changed to $_GET and my form action need to be changed not sure to what.

 

here is my ban.php file

<?
include("admin_code_header.php");


if ($_POST["DeletePost"]) {
    $id = $_GET["id"];
    $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
    mysql_query($query);
    echo "ID removed from system: ".$id;
  }


if ($_POST["BanIP"]) {
    $IP_To_Add = $_GET["ip"];
    
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
  }



?>
<html>
<form name="form" method="post" action="ban.php">

<input name="DeletePost" type="submit" id="DeletePost" value="Delete">

<input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $_GET['ip'];?>">
    </form>
</html>

  • Solution

 

Ok so I spend some more time with the script and made a few more changes. The options display now but nothing happens when I try to execute them.

First of all I added the ip to my URL as well

 and made a few changes in my ban.php file like the $_POST changed to $_GET and my form action need to be changed not sure to what.

 

here is my ban.php file

<?
include("admin_code_header.php");


if ($_POST["DeletePost"]) {
    $id = $_GET["id"];
    $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
    mysql_query($query);
    echo "ID removed from system: ".$id;
  }


if ($_POST["BanIP"]) {
    $IP_To_Add = $_GET["ip"];
    
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
  }



?>
<html>
<form name="form" method="post" action="ban.php">

<input name="DeletePost" type="submit" id="DeletePost" value="Delete">

<input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $_GET['ip'];?>">
    </form>
</html>

 

Ok so I fixed my script yay

<?
$conn = mysql_connect('*********','************','*********') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('*********',$conn) or trigger_error("SQL", E_USER_ERROR);



if ($_POST["DeletePost"]) {
    $id = $HTTP_GET_VARS["id"];
    $query = "DELETE FROM StringyChat WHERE id ='".$id."'"; 
    mysql_query($query);
    echo "ID removed from system: ".$id;
  }


if ($_POST["BanIP"]) {
    $IP_To_Add = $HTTP_GET_VARS["ip"];
    
      $sql = "INSERT INTO StringyChat_IPBan (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
  }

if ($_POST["Unban"]) {

$IP_To_Remove = $HTTP_GET_VARS['ip'];
      $query = "DELETE FROM StringyChat_IPBan WHERE ip ='".$IP_To_Remove."'"; 
      mysql_query($query);
      echo "IP Removed from ban list: ".$IP_To_Remove;

  }



?>
<html>
<form name="form" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>">
<br>
<input name="DeletePost" type="submit" id="DeletePost" value="Delete Message"><br><br>

<input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $HTTP_GET_VARS['ip'];?>">
<br><br>

<input name="Unban" type="submit" id="Unban" value="Unban <? echo $HTTP_GET_VARS['ip'];?>">

    </form>
<br><br>
<a href="page.php">Back</a>
</html>

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.