...

View Full Version : No database selected, wtf?



xxcorrosionxx
09-17-2011, 12:15 PM
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
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


<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 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

kbluhm
09-17-2011, 01:30 PM
http://www.php.net/mysql_select_db

tangoforce
09-17-2011, 04:35 PM
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 :eek:


<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'test');
define('DB_PASSWORD', 'test123');
define('DB_DATABASE', 'test');

if (mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
mysql_select_db(DB_DATABASE); //You were missing this
}
else
{
die(mysql_error());
}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum