1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Mqsql database panel

Discussion in 'PHP' started by flapstik1, Apr 12, 2013.

  1. #1
    Hello I am trying to make a table on my website that allows me to see the keys in my database I currently have this code

    $username="N/A";
    $password="N/A";
    $database="N/A";
    $host="N/A";
    $dbConn = mysql_connect($host, $username, $password, $database)
    or die("Could not connect: " + mysql_error());
    mysql_select_db($database, $dbConn)
    or die("Could not find database: " + mysql_error());
     
     
    $txt = "<table align=\"center\">";
        $txt .= "<tr><td>KeyCode</td><td>Date</td><td>Sold</td><td>Email</td></tr>";
        $sql = "SELECT * FROM `benkeys` where id = 1";
    $res = mysql_query($sql, $dbConn)
    or die(mysql_error());
    if($res && mysql_num_rows($res)) {
    }
     
    mysql_close($dbConn);
            $cal = "js_del_key('".$row["keycode"]."'); return false;";
            $txt .= "<tr><td>".$row['keycode']."</td><td>".$row['datum']."</td>";
            $txt .= "<td>".$row['sold']."</td><td>".$row['email']."</td>";
            $txt .= "<td><input type=\"button\" name=\"del\" value=\"DELETE\" onclick=\"".$cal."\"></td></tr>";
     
        $cal = "js_add_key(); return false;";
        $txt .= "<tr><td><input type=\"text\" size=\"46\" id=\"nkey\" /></td><td>".date("Y-m-d")."</td>";
        $txt .= "<td>N</td><td>&nbsp;</td>";
        $txt .= "<td><input type=\"button\" name=\"addkey\" value=\"ADD NEW\" onclick=\"".$cal."\"></td></tr>";
        $txt .= "</table>";
        mysql_close($link);
        return($txt);
     
    function p_adm_del_key($key)
    {
        $link = dbconnect();
        $sql = "delete from `benkeys` where `keycode`='".$key."' limit 1";
        mysql_query($sql);
        mysql_close($link);
        return(p_adm_list_keys());
    }
    function p_adm_add_key($key)
    {
        $link = dbconnect();
        $sql = "insert into `benkeys` (`keycode`,`datum`,`sold`) values ('".$key."','".date("Y-m-d")."','N')";
        mysql_query($sql);
        mysql_close($link);
        return(p_adm_list_keys());
    }
    function dbconnect()   
    {
        $link = mysql_connect(DBHOST, DBUSER, DBPWD) or die ("Error: ".mysql_error());
        mysql_select_db(DBNAME) or die("Could not select database: ".mysql_error());
        return($link);
    }
    ?>
    Code (markup):
    I don't get any errors but no table shows please help.
     
    flapstik1, Apr 12, 2013 IP
  2. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #2
    You forgot to use
    $row=mysql_fetch_assoc($res);
     
    ChiragKalani, Apr 12, 2013 IP
  3. flapstik1

    flapstik1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Where would I put that?
     
    flapstik1, Apr 12, 2013 IP
  4. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #4
    on line number 18.
     
    ChiragKalani, Apr 12, 2013 IP
  5. flapstik1

    flapstik1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Ok fixed taht but nothing shows on the page
     
    flapstik1, Apr 12, 2013 IP
  6. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #6
    Could you export the table in SQL and send it to me? so that I can check locally on my PC.
     
    ChiragKalani, Apr 12, 2013 IP
  7. flapstik1

    flapstik1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Ill pm you details there's nothing in there to steal rly.
     
    flapstik1, Apr 12, 2013 IP
  8. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #8
    Here is the updated code:

    <?php
     
    $username="root";
    $password="";
    $database="test";
    $host="localhost";
    $dbConn = mysql_connect($host, $username, $password, $database)
    or die("Could not connect: " + mysql_error());
    mysql_select_db($database, $dbConn)
    or die("Could not find database: " + mysql_error());
     
     
    $txt = "<table align=\"center\">";
        $txt .= "<tr><td>KeyCode</td><td>Date</td><td>Sold</td><td>Email</td></tr>";
        $sql = "SELECT * FROM `benkeys`";
    $res = mysql_query($sql, $dbConn)
    or die(mysql_error());
    while($row=mysql_fetch_assoc($res))
    {
            $cal = "js_del_key('".$row["keycode"]."'); return false;";
            $txt .= "<tr><td>".$row['keycode']."</td><td>".$row['datum']."</td>";
            $txt .= "<td>".$row['sold']."</td><td>".$row['email']."</td>";
            $txt .= "<td><input type=\"button\" name=\"del\" value=\"DELETE\" onclick=\"".$cal."\"></td></tr>";
     
        $cal = "js_add_key(); return false;";
        $txt .= "<tr><td><input type=\"text\" size=\"46\" id=\"nkey\" /></td><td>".date("Y-m-d")."</td>";
        $txt .= "<td>N</td><td>&nbsp;</td>";
        $txt .= "<td><input type=\"button\" name=\"addkey\" value=\"ADD NEW\" onclick=\"".$cal."\"></td></tr>";
    }
        $txt .= "</table>";
        echo $txt;
       
     
    function p_adm_del_key($key)
    {
        $link = dbconnect();
        $sql = "delete from `benkeys` where `keycode`='".$key."' limit 1";
        mysql_query($sql);
        mysql_close($link);
        return(p_adm_list_keys());
    }
    function p_adm_add_key($key)
    {
        $link = dbconnect();
        $sql = "insert into `benkeys` (`keycode`,`datum`,`sold`) values ('".$key."','".date("Y-m-d")."','N')";
        mysql_query($sql);
        mysql_close($link);
        return(p_adm_list_keys());
    }
    function dbconnect() 
    {
        $link = mysql_connect('localhost', 'root', '') or die ("Error: ".mysql_error());
        mysql_select_db('test') or die("Could not select database: ".mysql_error());
        return($link);
    }
    ?>
    PHP:
     
    ChiragKalani, Apr 12, 2013 IP