Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    117
    Thanks
    27
    Thanked 0 Times in 0 Posts

    No database selected, wtf?

    Ok when i go to submit content inside my script (using it to test it out) it says no database selected. But i wrote the config file and passed it through. Here is my source:

    config.php

    PHP Code:
    <?php
        define
    ('DB_HOST''localhost');
        
    define('DB_USER''test');
        
    define('DB_PASSWORD''test123');
        
    define('DB_DATABASE''test');
        
    if ( !@
    mysql_connect($localhost$dbuser$dbpass ) ) die(mysql_error()); 

    ?>

    This is where people will submit content to a table called: documents

    index.php

    PHP Code:
    <html>
    <head>
    <title>Milworm - Submit A Document</title>
    <meta name="description" content="milw0rm exploits and 0day exploits database">
    <meta name="keywords" content="exploits code, exploit code, exploits, 0-day, 0day, 0days, exploit, zero day, poc, exploit, local exploits, remote exploits, root exploits, windows, linux, new exploits, latest exploits, shellcode, Zero-day, zeroday, security articles, ezines, zines, security papers">

    <link type="text/css" rel="stylesheet" href="./b0x.css">

    <link rel="alternate" type="text/xml" title="milw0rm - RSS Feed" href="http://milw0rm.com/rss.php">

    <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon">
    <style type="text/css">
    <!--
    .style17 {font-weight: bold}
    -->
    </style>
    </head>

    <body dir="ltr" alink="#00ff00" background="../dot.gif" bgcolor="#000000" link="#00c000" text="#008000" vlink="#00c000">

    <center>
    <?php 

    include "config.php";
    $tarih date("d-m-Y");
    if ( !isset(
    $_POST['Submit']) ) { 
    ?> 
    <form method="post" action="">
            <table width="676">
              <tr>
                <td width="668" height="47"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="224" height="33"><input name="baslik" type="text" id="baslik" style="width: 222px;" maxlength="50" value="Title" />
                      <input name="sayfa_adi" type="text" id="sayfa_adi" style="width: 222px;" value="Author" /></td>
                      <td width="52"><div align="center"><a href="../cpanel.php"><img src="../admin_img/home.gif" alt="asdasdasd" width="31" height="31" border="0"></a></div></td>
                      <td width="51"><div align="center"><a href="../haber"><img src="../admin_img/duyuru.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="56"><div align="center"><a href="../webapps"><img src="../admin_img/scriptler.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="43"><div align="center"><a href="../local"><img src="../admin_img/cserial.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="49"><div align="center"><a href="../video"><img src="../admin_img/download.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="70"><div align="center"><a href="../shellcode"><img src="../admin_img/reklam.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="70"><div align="center"><a href="../dokuman"><img src="../admin_img/dokuman.gif" width="31" height="31" border="0"></a></div></td>
                      <td width="53"><div align="center"><a href="../ban"><img src="../admin_img/yasak.gif" width="31" height="31" border="0"></a></div></td>
                    </tr>
                    <tr>
                      <td><input name="tarih" type="text" id="tarih" style="width: 158px;" value="<?php echo $tarih ?>" />
                      <input type="submit" name="Submit" value="Submit" /></td>
                      <td><div align="center"><span class="style17"><a href="../cpanel.php">Admin</a></span></div></td>
                      <td><div align="center"><strong><a href="../haber">Have</a></strong></div></td>
                      <td><div align="center"><strong><a href="../webapps">Exploits</a></strong></div></td>
                      <td><div align="center"><strong><a href="../local" target="_self">Local</a></strong></div></td>
                      <td><div align="center"><strong><a href="../video">Videos</a></strong></div></td>
                      <td><div align="center"><strong><a href="../shellcode">Shell Codes</a></strong></div></td>
                      <td><div align="center"><strong><a href="../dokuman">Documents</a></strong></div></td>
                      <td><div align="center"><strong><a href="../ban">Ip Ban</a></strong></div></td>
                    </tr>
                  </table>
                 
                </p></td>
              </tr>
              <tr>
                <td height="62"><textarea name="icerik" id="icerik" style="width: 666px; height: 444px;"></textarea>            </td>
              </tr>
        </table>
            </td>
    <td><BR></td>
            </tr> 
        <tr> 
        <td valign="top">&nbsp;</td> 
        <td>&nbsp;</td>
        </tr> 
      
      <tr> 
        <td valign="top">&nbsp;</td>
        <td>&nbsp;</td> 
      </tr> 
    </table> 
    </form> 
    <?php 


    else if ( isset(
    $_POST['sayfa_adi']) && isset($_POST['baslik']) && isset($_POST['icerik']) && isset($_POST['tarih']) && $_POST['sayfa_adi'] && $_POST['baslik'] && 


    $_POST['icerik'] && $_POST['tarih']) { 
        
        
        
    $result mysql_query('INSERT INTO `dokumanlar` ( `id`, `sayfa_adi`, `baslik`, `icerik`, `tarih`, `sayac` ) VALUES ( NULL, \'' 
        
        
    $_POST['sayfa_adi'] . '\', \'' $_POST['baslik'] . '\', \'' $_POST['icerik'] . '\', \'' $_POST['tarih'] . '\' , 0 );'); 
       
       
        if ( 
    $result ) echo '
        <center><table width="800" border="0" cellpadding="3" cellspacing="3" class="main">
      <tr><td><img src="../admin_img/scriptler.gif"><br><br>
        New page added. </br>[ <a href="index.php">Add again</a> ] - [ <a href="../cpanel.php">cPanel</a> ] - [ <a href="../../index.php">Home</a> ]
        
        </tr></td>
    </table></center>'

        else echo 
    mysql_error(); 

    else echo 
    'Please fill in all fields'
    ?></center>
    </body></html>
    documents_sli.php

    PHP Code:
    <?php include "config.php"?>

    <?php

    $id 
    $_GET["id"];

    @
    mysql_unbuffered_query("DELETE FROM documents where id = '$id'"); 

    echo 
    '<link type="text/css" rel="stylesheet" href="./images/style.css">
    <link rel="alternate" type="text/xml" title="milw0rm - RSS Feed" href="http://milw0rm.com/rss.php">
    <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon"></head>
    <body dir="ltr" alink="#00ff00" background="dot.gif" bgcolor="#000000" link="#00c000" text="#008000" vlink="#00c000">
    <center>
    Silme islemi basariyla gerçeklersti. <br> <a href="index.php">[ Return to Main Page ]</a> - <a href="ekle.php">[ Exploit Ekle ]</a></center>
    </body></html>'



    ?>
    - Very bad php coder, thank you for help

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    First you are using an if followed by the code to run - die() which will ALWAYS die with an error because you have no selected your database.

    You've connected, thats the start. Now.. you could have 6 databases inside the database server - each for different projects. Which one do you want to use? - This is called selecting the database.

    Also, look at your code again - you've defined constants for your database and then used variables to connect to it

    PHP Code:
    <?php
        define
    ('DB_HOST''localhost');
        
    define('DB_USER''test');
        
    define('DB_PASSWORD''test123');
        
    define('DB_DATABASE''test');
        
    if (
    mysql_connect(DB_HOSTDB_USERDB_PASSWORD))
       {
       
    mysql_select_db(DB_DATABASE); //You were missing this
       
    }
    else
       {
       die(
    mysql_error());
       }

    ?>
    I can't really think of anything to write here now...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •