+ Reply to Thread
Results 1 to 5 of 5

Thread: Button not working :(

  1. #1
    martynball is offline x10Hosting Member martynball is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Stoke-on-Trent, UK
    Posts
    60

    Button not working :(

    Any idea why the ip_s button won't delete all posts with that IP and add the IP to the other table?

    PHP Code:
    <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 Code:
    <?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();
    }
    ?>

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Button not working :(

    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 by misson; 11-28-2009 at 09:57 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    martynball is offline x10Hosting Member martynball is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Stoke-on-Trent, UK
    Posts
    60

    Re: Button not working :(

    Okay, cheers. I will start to do that

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Button not working :(

    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 by misson; 11-28-2009 at 10:55 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    martynball is offline x10Hosting Member martynball is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Stoke-on-Trent, UK
    Posts
    60

    Re: Button not working :(

    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 by martynball; 11-29-2009 at 10:25 AM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. creating button images
    By miocene2 in forum Programming Help
    Replies: 3
    Last Post: 07-30-2009, 07:01 PM
  2. Regex radio button validation not working...
    By jbdesign in forum Programming Help
    Replies: 0
    Last Post: 05-28-2009, 12:12 PM
  3. Site not working
    By catro in forum Free Hosting
    Replies: 3
    Last Post: 12-25-2007, 11:59 AM
  4. www still not working
    By omaolligain in forum Free Hosting
    Replies: 6
    Last Post: 12-04-2007, 10:56 PM
  5. Subdomain Not Working
    By ak007 in forum Free Hosting
    Replies: 5
    Last Post: 06-12-2005, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers