Jump to content

[SOLVED] No database selected


jrws

Recommended Posts

Can someone help me with this error? I am trying to make an activate account page and ever time I attempt to test it I get the error that no database is selected. I have checked all my files, the database exists, I am using XAMPP.

Please tell me what files you want, because I don't know what to post.

Here are all the files so far that I am using:

config.php

functions.php

register.php

Link to comment
Share on other sites

For some reason there wasn't an edit button I could find for the first post, so instead I will just paste the three files;

config.php

<?php 
$host = 'localhost';
$db = 'new_news_system';
$user = 'root';
$pass = '';
$siteURL = 'http://localhost/news_system/';
$connect = mysql_connect($host,$user,$pass)or die(mysql_error());
$db = mysql_select_db($db,$connect)or die(mysql_error());

?>

 

functions.php

<?php
session_start();
require_once ('config.php');
//Functions
function encrypt($x, $salt = null)
{ //Simply encrypts a string using md5 and sha1
    if ($salt == null) {
        $x = md5(sha1($x));
        return $x;
    } else {
        $x = md5(sha1($x . $salt));
        return $x;
    }
}


function clean($string)
{
    if (get_magic_quotes_gpc()) {
        $string = stripslashes($string);
    } elseif (!get_magic_quotes_gpc()) {
        $string = addslashes(trim($string));
    }
    $string = trim($string);
    $string = escapeshellcmd($string);
    $string = mysql_real_escape_string($string);
    $string = stripslashes(strip_tags(htmlspecialchars($string)));
    return $string;
}
function valid_email($email)
{
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
        // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
        return false;
    }
    // Split it into sections to make life easier
    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
        if (!ereg("^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
            $local_array[$i])) {
            return false;
        }
    }
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
        $domain_array = explode(".", $email_array[1]);
        if (sizeof($domain_array) < 2) {
            return false; // Not enough parts to domain
        }
        for ($i = 0; $i < sizeof($domain_array); $i++) {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
                return false;
            }
        }
    }
    return true;
}

function usernameExists($user){
$mysql_query = "SELECT * FROM user WHERE username = '$user'";
$mysql_result = mysql_query($mysql_query)or die('Error: '.mysql_error());
if(mysql_num_rows($mysql_result)>0){
	return true;
}else{
	return false;
}
}
function activationEmail($email,$code){

$to = $email;
$sub = 'Activation at NewsSystem';
$mes = 'Hello there, welcome to News-System!<br>';
$mes .= 'So the first step is to activate your account, so that you may login.';
$mes .='\n Go to this adress:\n';
$mes .='<a href="'.$siteURL.'/register?activate='.$code.'"';
$send = mail($to,$sub,$mes,$headers);
if(!$send){
	return false;
}else{
	return true; 
}
}

?>

 

register.php

<?php
//Register page Will have ajax eventually
include_once 'lib/functions.php'; ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Register</title>
	<link rel="stylesheet" type="text/css" href="lib/default.css">
	</head>

<body><div class="holder"><?
if ($_SESSION['username'] != '')
{
   echo 'You are already logged in!';
} else{
if (isset($_GET['code']))
   {
       $code = clean($_GET['code']);
       $query = "SELECT code FROM user WHERE code = '$code'";
       echo $query;
       $resultA= mysql_query($query)or die(mysql_error());
       	if (mysql_num_rows($resultA)>0)
       	{
           		$query = "UPDATE user SET u_level = 1, code ='' WHERE code = '$code' ";
           		$resultQuery = mysql_query($query) or die(mysql_error());
           			if ($resultQuery)
           					{
               			echo 'Successfully activated, <a href="' . $siteURL . '/login.php">login</a>';
           					} else{
               echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>';
           						  }
       } else{
           echo '<div id="error">Code does not exist! Please check that you cannot already log in</div>';
}
?>


	<?


       }
}
?></div>
</body></html>

 

Please note this is a testing server, and as such I haven't changed the user name and password information.

EDIT:

How do you expect top be assisted when u dont show the codes. R u using Jpmaster77 login framework?

No I am not.

Link to comment
Share on other sites

From the errors below i c u did not post all files. Have u included functions.php correctly

 

Warning: include_once(lib/functions.php) [function.include-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\testsite\register.php on line 3

 

Warning: include_once() [function.include]: Failed opening 'lib/functions.php' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\testsite\register.php on line 3

Link to comment
Share on other sites

From the errors below i c u did not post all files. Have u included functions.php correctly

 

Warning: include_once(lib/functions.php) [function.include-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\testsite\register.php on line 3

 

Warning: include_once() [function.include]: Failed opening 'lib/functions.php' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\testsite\register.php on line 3

That's because I had made functions in the folder lib along with config.

Link to comment
Share on other sites

For some reason there is no edit button. Anyway, I found an answer to my problem although it is not exactly what I desired;

Include config and functions separately.

 

This is all I needed to change, however I still don't understand what was wrong, so I would still appreciate an answer.

 

Thanks for you help

-James-

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.