Button not working :(

martynball

New Member
Messages
60
Reaction score
0
Points
0
Any idea why the ip_s button won't delete all posts with that IP and add the IP to the other table?

PHP:
<body>
<p style="color:#CCCCCC; font-family:Calibri; font-size:36px;" align="center">Administrator Tools</p>
<?php include "../scripts/db-connect.php"; ?>
<?php include "../scripts/delete.php"; ?>
<?php include "../scripts/ban.php"; ?>
<div style="overflow:scroll; height:50%; width:50%; overflow-x:hidden; margin:0 auto; background-color:#161616;">
<?php
//Get data...
$result = mysql_query("
SELECT * from commentTable 
ORDER BY date DESC
");
while ($row = mysql_fetch_array($result))
{ 
$id=$row["ID"];
$name=$row["NAME"];
$message=$row["MESSAGE"];
$email=$row["EMAIL"];
$today= $row["DATE"];
$ip=$row["IP"];

//Display results
    echo "<table class=\"comment-table\">";
    echo "<tr>";
    echo "<td class=\"comment-name\">Posted by: $name<div class=\"comments-date\">$today</div></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><p class=\"comment-message\"/>$message</p>";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td class=\"comment-id\">ID: $id";
    echo "<form method=\"post\" class=\"del-form\"><input name=\"id\" id=\"id\" type=\"hidden\" value=\"$id\"><input type=\"image\" src=\"../images/del.png\"></form></td>"; 
    echo "</tr>";
    echo "</table>";
    echo "<center><form method=\"post\" class=\"ban-ip-f\"><input name=\"ip_s\" id=\"ip_s\" type=\"hidden\" value=\"$ip\"><input type=\"button\" class=\"ban-ip\" value=\"$ip\"></form></center>";
    echo "<br />";
}
?>
</div>
</body>
</html>

ban.php
PHP:
<?php
if (isset($_POST['ip_s'])) {
$ip = mysql_real_escape_string($_POST['ip']);
$statement = "DELETE FROM commentTable WHERE IP='$ip'";
$result = mysql_query ($statement);
    echo "<center><div class=\"deleted\">Banned and deleted all comments from $ip.</div></center>";
    }
    // BAN IP ADDRESS -----------------------------------------------
// Make varibles
$ip = mysql_real_escape_string($_POST['ip']);

if (isset($_POST['ip_s'])) {
// Insert data
$query="INSERT INTO banList (IP) VALUES ('".$ip."')";
$result = mysql_query ($query);
}
else {
    echo "<p class=\"Error\"/>Error!</p>" .mysql_error();
}
?>
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
In the form and at the start of ban.php, you refer to the field as "ip_s", but you refer to the field as "ip" when you pass it to mysql_real_escape_string().

You should really learn some debugging techniques. If you added statement to print out variables ($ip, $statement) at various stages in the script, you could have easily caught this yourself. var_dump and print_r are very useful for objects and arrays; strings and numbers just need a print or echo.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Some terminology: code that's used solely during development (such as printing variables) is called "scaffolding".

Once you're more familiar with the development process, you can learn live debugging. It gives you more control over the debugging process, lets you more easily observe what's happening and requires less work on your part (no need to write scaffolding), but requires more complex software. You need a web stack (e.g. XAMPP or WAMP), a remote debugging extension (e.g. XDEBUG) and an IDE (e.g. Eclipse for PHP developers, or Eclipse with the PDT plugin). Eclipse has a steep learning curve, which is why I don't recommend trying it now. You might want to try Notepad++ with XDEBUG; I haven't used it, so I can't speak to its ease of use.
 
Last edited:

martynball

New Member
Messages
60
Reaction score
0
Points
0
I think I will stick to scaffolding, seeming as this website is probably my first proper one and I am not aiming on learning a LOT of web design. My intentions are to go into the gaming industry, 3d modelling.

This website will be my portfolio, at the moment it is for college work, all I really need to do is change the images in the downloads and gallery pages and change the banner.
Edit:
Never mind, got it working.
 
Last edited:
Top