My SQL could not select Database!

I’m creating a simple Login/Registration site. I’m having a small problem with one line that links the page to the database. when I click the register button it says “My SQL could not select Database!”

My database page
[php]

<?php $host = "localhost"; $user = "abed"; $pass = ""; $database = "user_db"; //You can create a database of your choice. $connection = mysql_connect($host, $user, $pass) or die ("Couldn't connect to database"); mysql_select_db ($database); mysql_query ("CREATE TABLE `user_db`.`Users` ( `id` INT NOT NULL AUTO_INCREMENT , `username` VARCHAR( 20 ) NOT NULL , `password` VARCHAR( 20 ) NOT NULL , `email` VARCHAR( 400 ) NOT NULL , `birth` YEAR NOT NULL , PRIMARY KEY ( `id` ))"); die("Table has been created. DO NOT RUN THIS SCRIPT AGAIN!"); ?>

?>

[/php]

Register.php

[php]

Email: Username: Password: Re-type Password: Birth Year:

[/php]

Finish.php

[php]

<?php //STEP 1 Connect To Database $connect = mysql_connect("localhost","abed","", "user_db"); if (!$connect) { die("MySQL could not connect!"); } $DB = mysql_select_db('database'); if(!$DB) { die("My SQL could not select Database!"); } //STEP 2 Declare Variables $Username = $_POST['username']; $Email = $_POST['email']; $Email1 = "@"; $Email_Check = strpos($Email,$Email1); $Password = $_POST['password']; $Re_Password = $_POST['re-password']; $Birth = $_POST['birth']; //STEP 3 Check To See If All Information Is Correct if($Username == "") { die("Opps! You don't enter a username!"); } if($Password == "" || $Re_Password == "") { die("Opps! You didn't enter one of your passwords!"); } if($Birth == "") { die("Opps! You never entered in your birth year!"); } if($Password != $Re_Password) { die("Ouch! Your passwords don't match! Try again."); } if($Email_Check === false) { die("Opps! That's not an email!"); } //STEP 4 Insert Information Into MySQL Database if(!mysql_query("INSERT INTO users (email, username, password, birth) VALUES ('$Email', '$Username', '$Password', '$Birth')")) { die("We could not register you due to a mysql error (Contact the website owner if this continues to happen.)"); } ?>

[/php]

[php]
$connect = mysql_connect(“localhost”,“abed”,"", “user_db”);
if (!$connect)
{
die(“MySQL could not connect!”);
}

$DB = mysql_select_db(‘database’);
[/php]

Is this your actual code? According to your first block it should be:

[php]
$connect = mysql_connect(“localhost”,“abed”,"");
if (!$connect)
{
die(“MySQL could not connect!”);
}

$DB = mysql_select_db(‘user_db’);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service