Please tell me tables to be created as per this php code

Discussion in 'Databases' started by seopriest, Mar 18, 2012.

  1. #1
    Hi

    by fault ive lost mysql of my banned Ip table and got only this code available

    please tell me mysql command to run in mysql to make reqd tables ...

    <?php
    
    include("../include/config.php");
    include_once("../include/functions/import.php");
    verify_login_admin();
    
    if($_GET['add']){
    $sql = "insert into ban_ip (ip) values ('".mysql_real_escape_string($_GET['ip'])."')";
    $conn->execute($sql);
    
    } elseif($_GET['delete']) {
    
    $sql = "delete from ban_ip where id='".$_GET['delete']."'";
    $conn->execute($sql);
    
    }
    
    $query2 = "SELECT * from ban_ip";
    $executequery2 = $conn->Execute($query2);
    if($executequery2) $results = $executequery2->getrows();
    
    Stemplate::assign('results',$results);
    STemplate::display("administrator/global_header.tpl");
    STemplate::display("administrator/banned.tpl");
    STemplate::display("administrator/global_footer.tpl");
    ?>
    Code (markup):

    thanks

    regards

    SEOPrist
     
    seopriest, Mar 18, 2012 IP
  2. RobertStev

    RobertStev Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ban_ip looks like the only row needed
     
    RobertStev, Mar 18, 2012 IP
  3. seopriest

    seopriest Member

    Messages:
    347
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #3
    what should be the query to run in it :)
     
    seopriest, Mar 18, 2012 IP
  4. searchesuk

    searchesuk Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi in this code only 1 row is needed, which have the id =1,
     
    searchesuk, Mar 18, 2012 IP
  5. mrandre

    mrandre Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    here is the total php system you need to run it..
    connect.php
    <?php
    $hostname='***'; //// specify host, i.e. 'localhost'
    $user='****'; //// specify username
    $pass='****'; //// specify password
    $dbase='****'; //// specify database name
    $connection = mysql_connect("$hostname" , "$user" , "$pass")
    or die ("Can't connect to MySQL");
    $db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
    ?>

    add.php
    <form id="FormName" action="added.php" method="post" name="FormName">
    <table width="448" border="0" cellspacing="2" cellpadding="0">

    <tr>
    <td width="150" align="right"><label for="ip">ip</label></td>
    <td><input name="ip" maxlength="15" type="text" value="<?php echo stripslashes($ip) ?>"></td>
    </tr>

    <tr>
    <td colspan="2" align="center"><input name="" type="submit" value="Add"></td>
    </tr>

    </table>
    </form>


    <?php
    include("connect.php");

    $ip = trim(mysql_real_escape_string($_POST["ip"]));

    $results = mysql_query("INSERT INTO ban_ip (id, ip)
    VALUES ('', '$ip')");

    if($results) { echo "Successfully Added"; } else { die('Invalid query: '.mysql_error()); }

    ?>

    updated.php
    <?php
    include("connect.php");

    $id = $_REQUEST['id'];

    $c_Z = mysql_query("SELECT * FROM ban_ip WHERE id = '$id' ");
    $r_Z = mysql_fetch_array($c_Z);
    extract($r_Z);
    ?>

    <form id="FormName" action="updated.php" method="post" name="FormName">
    <table width="448" border="0" cellspacing="2" cellpadding="0">

    <tr>
    <td width="150" align="right"><label for="ip">ip</label></td>
    <td><input name="ip" maxlength="15" type="text" value="<?php echo stripslashes($ip) ?>"></td>
    </tr>

    <tr>
    <td colspan="2" align="center"><input name="" type="submit" value="Update"></td>
    </tr>

    </table>
    </form>

    index.php
    <a href="add.php">Add entry</a><br>
    <br>

    <?php
    include("connect.php");

    $result = mysql_query("SELECT * FROM ban_ip ");
    $num = mysql_num_rows ($result);
    mysql_close();

    if ($num > 0 ) {
    $i=0;
    while ($i < $num) {

    $ip = stripslashes(mysql_result($result,$i,"ip"));

    $row .= '<tr>
    <td><a href="update.php?id=$id">ip</a></td>
    <td><a href="delete.php?id=$id">Delete</a></td>
    </tr>';

    ++$i; }} else { $row = '<tr><td colspan="2" align="center">Nothing found</td></tr>'; }
    ?>
    <table border="1" cellpadding="3" cellspacing="0"><? echo $row ?></table>

    delete.php
    <?php
    include("connect.php");

    $id = $_GET['id'];

    mysql_query("DELETE FROM ban_ip WHERE id = '$id' ");
    mysql_close();

    echo "Entry deleted";
    ?>


    and the database
    CREATE TABLE `ban_ip` (
    `id` int(6) NOT NULL auto_increment,
    `ip` varchar(15) NOT NULL default '',
    PRIMARY KEY (`id`),
    UNIQUE KEY `id` (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=1 ;
     
    mrandre, Apr 1, 2012 IP