Jump to content

MySQL Error, first time at WAMP!


3raser

Recommended Posts

I get a "No database selected" error whenever I submit information on my register.php page, which is:

 

<?php

include_once('includes/config.php');
include_once('functions.php');

$return_content = AccountRelated(null, null, 3);

?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<title><?php echo $title; ?></title>
</head>
<body>

<div class="logo"><a href="index.php"><img src="style/images/logo.png" border="0"></a></div>

<center>

<div class="background">

<div class="container">
<?php echo $return_content; ?>
</div>

</div>
</center>

</body>
</html>

 

But after I click submit, I get the "No database selected" error, but using WAMP, I include config.php which holds the following details:

 

<?php

$title = "NovaUpload - File Uploader";

mysql_connect("localhost", "", "");
mysql_select_db("data");

?>

 

And if functions.php is required, here:

 

<?php

function AccountRelated($username, $password, $query_type)
{

if($query_type == 1)
{
	$set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error());

	//user must not exist
	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = 'Sorry, no information was found';

	}
	else
	{
		$grab = mysql_fetch_assoc($set_query);

		//login information
		if($grab['COUNT(d.username)'] > 0)
		{
			$welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!";
		}
		else
		{	
			$welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!";
		}
	}
}
elseif($query_type == 2)
{
	$set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20");

	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = "Sorry, there are currently no files uploaded to view.";

	}
	else
	{
		//display all files
		while($row = mysql_fetch_assoc($set_query) == 0)
		{
			echo $row['title']."<br/>";
		}

	}	
}
elseif($query_type == 3)
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = sha1(sha1(md5($_POST['password'])));

	if(!$username || !$password)
	{
		$return_content = "All fields are required! <table><form action='register.php' method='POST'>
		<tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr>
		<tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr>
		<tr><td><input type='submit' value='Register'></td></tr>
		</form></table>";
	}
	else
	{
		$set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1");

		if(mysql_num_rows($set_query) == 0)
		{
			$return_content = "You have successfully registered the account ". $username ." with the
			password ". $_POST['password'] ."!";

			mysql_query("INSERT INTO users VALUES (null, '$username', '$password', 0, 0, '". date("M-d-Y") ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error());
		}
		else
		{
			$return_content = "An account with this username already exists.";
		}
	}
return $return_content;
}
else
{
	//nothing to process
}
}
?>

Link to comment
Share on other sites

I get a "No database selected" error

I hate to be Cap. Obvious, but this would mean you haven't selected a database.

Database are selected, in PHP, using the function mysql_select_db

you don't have to assign it to a variable either... once you call the function, the database is used until you call that function again or you close the connection.

Link to comment
Share on other sites

I get a "No database selected" error

I hate to be Cap. Obvious, but this would mean you haven't selected a database.

Database are selected, in PHP, using the function mysql_select_db

you don't have to assign it to a variable either... once you call the function, the database is used until you call that function again or you close the connection.

 

Did you read my whole post? <.<

Link to comment
Share on other sites

try using this format with wamp

 

$mysql = $wowdb->connect($db_host, $db_user, $db_passwd, $db_name);

$db = mysql_select_db($db_name);

 

if(!$mysql) die("Can´t connect to MySql!<br>".mysql_error()." ".mysql_errno());

if(!$db) die("Can´t connect to MySql Database!<br>".mysql_error()." ".mysql_errno());

Link to comment
Share on other sites

No, my database is not spelled wrong.

 

Also, I tried this:

 

<?php

$title = "NovaUpload - File Uploader";

$mysql = $wowdb->connect("localhost", "", "", "data");
$db = mysql_select_db("data");

if(!$mysql) die("Can´t connect to MySql!<br>".mysql_error()." ".mysql_errno());
if(!$db) die("Can´t connect to MySql Database!<br>".mysql_error()." ".mysql_errno())

?>

 

But I get a blank page for some reason. o.O

 

Is it possible when functions.php is loaded, config.php is out of range? But I tried adding the config.php contents inside functions.php, and it still didn't work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.