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

    Code (Text):
    1. $username="N/A";
    2. $password="N/A";
    3. $database="N/A";
    4. $host="N/A";
    5. $dbConn = mysql_connect($host, $username, $password, $database)
    6. or die("Could not connect: " + mysql_error());
    7. mysql_select_db($database, $dbConn)
    8. or die("Could not find database: " + mysql_error());
    9.  
    10.  
    11. $txt = "<table align=\"center\">";
    12.     $txt .= "<tr><td>KeyCode</td><td>Date</td><td>Sold</td><td>Email</td></tr>";
    13.     $sql = "SELECT * FROM `benkeys` where id = 1";
    14. $res = mysql_query($sql, $dbConn)
    15. or die(mysql_error());
    16. if($res && mysql_num_rows($res)) {
    17. }
    18.  
    19. mysql_close($dbConn);
    20.         $cal = "js_del_key('".$row["keycode"]."'); return false;";
    21.         $txt .= "<tr><td>".$row['keycode']."</td><td>".$row['datum']."</td>";
    22.         $txt .= "<td>".$row['sold']."</td><td>".$row['email']."</td>";
    23.         $txt .= "<td><input type=\"button\" name=\"del\" value=\"DELETE\" onclick=\"".$cal."\"></td></tr>";
    24.  
    25.     $cal = "js_add_key(); return false;";
    26.     $txt .= "<tr><td><input type=\"text\" size=\"46\" id=\"nkey\" /></td><td>".date("Y-m-d")."</td>";
    27.     $txt .= "<td>N</td><td>&nbsp;</td>";
    28.     $txt .= "<td><input type=\"button\" name=\"addkey\" value=\"ADD NEW\" onclick=\"".$cal."\"></td></tr>";
    29.     $txt .= "</table>";
    30.     mysql_close($link);
    31.     return($txt);
    32.  
    33. function p_adm_del_key($key)
    34. {
    35.     $link = dbconnect();
    36.     $sql = "delete from `benkeys` where `keycode`='".$key."' limit 1";
    37.     mysql_query($sql);
    38.     mysql_close($link);
    39.     return(p_adm_list_keys());
    40. }
    41. function p_adm_add_key($key)
    42. {
    43.     $link = dbconnect();
    44.     $sql = "insert into `benkeys` (`keycode`,`datum`,`sold`) values ('".$key."','".date("Y-m-d")."','N')";
    45.     mysql_query($sql);
    46.     mysql_close($link);
    47.     return(p_adm_list_keys());
    48. }
    49. function dbconnect()  
    50. {
    51.     $link = mysql_connect(DBHOST, DBUSER, DBPWD) or die ("Error: ".mysql_error());
    52.     mysql_select_db(DBNAME) or die("Could not select database: ".mysql_error());
    53.     return($link);
    54. }
    55. ?>
    I don't get any errors but no table shows please help.
    flapstik1, Apr 12, 2013 IP
  2. ChiragKalani

    ChiragKalani Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    48
    #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 Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    48
    #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 Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    48
    #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 Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    2
    Trophy Points:
    48
    #8
    Here is the updated code:

    PHP:
    1. <?php
    2.  
    3. $username="root";
    4. $password="";
    5. $database="test";
    6. $host="localhost";
    7. $dbConn = mysql_connect($host, $username, $password, $database)
    8. or die("Could not connect: " + mysql_error());
    9. mysql_select_db($database, $dbConn)
    10. or die("Could not find database: " + mysql_error());
    11.  
    12.  
    13. $txt = "<table align=\"center\">";
    14.     $txt .= "<tr><td>KeyCode</td><td>Date</td><td>Sold</td><td>Email</td></tr>";
    15.     $sql = "SELECT * FROM `benkeys`";
    16. $res = mysql_query($sql, $dbConn)
    17. while($row=mysql_fetch_assoc($res))
    18. {
    19.         $cal = "js_del_key('".$row["keycode"]."'); return false;";
    20.         $txt .= "<tr><td>".$row['keycode']."</td><td>".$row['datum']."</td>";
    21.         $txt .= "<td>".$row['sold']."</td><td>".$row['email']."</td>";
    22.         $txt .= "<td><input type=\"button\" name=\"del\" value=\"DELETE\" onclick=\"".$cal."\"></td></tr>";
    23.  
    24.     $cal = "js_add_key(); return false;";
    25.     $txt .= "<tr><td><input type=\"text\" size=\"46\" id=\"nkey\" /></td><td>".date("Y-m-d")."</td>";
    26.     $txt .= "<td>N</td><td>&nbsp;</td>";
    27.     $txt .= "<td><input type=\"button\" name=\"addkey\" value=\"ADD NEW\" onclick=\"".$cal."\"></td></tr>";
    28. }
    29.     $txt .= "</table>";
    30.     echo $txt;
    31.    
    32.  
    33. function p_adm_del_key($key)
    34. {
    35.     $link = dbconnect();
    36.     $sql = "delete from `benkeys` where `keycode`='".$key."' limit 1";
    37.     mysql_query($sql);
    38.     mysql_close($link);
    39.     return(p_adm_list_keys());
    40. }
    41. function p_adm_add_key($key)
    42. {
    43.     $link = dbconnect();
    44.     $sql = "insert into `benkeys` (`keycode`,`datum`,`sold`) values ('".$key."','".date("Y-m-d")."','N')";
    45.     mysql_query($sql);
    46.     mysql_close($link);
    47.     return(p_adm_list_keys());
    48. }
    49. function dbconnect()
    50. {
    51.     $link = mysql_connect('localhost', 'root', '') or die ("Error: ".mysql_error());
    52.     mysql_select_db('test') or die("Could not select database: ".mysql_error());
    53.     return($link);
    54. }
    55. ?>
    ChiragKalani, Apr 12, 2013 IP