No database selected
Posted by: triplem (109.255.44.---)
Date: June 20, 2013 01:51PM

I using a register form and when I click submit I get this "No database selected" don't know where I'm going wrong: I'm using a wamp server
Here is the code I'm using!

<!doctype html>
<html lang="en">
<?php session_start(); ?>

<head>
<script language="JavaScript">

<!-- Begin
function validatePwd(){
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var password = document.form.myForm.password.value;
var confirmpassword = document.form.myForm.confirmpassword.value;

// check for a value in both fields.
if (password == '' || confirmpassword == '') {
alert('Please enter your password twice.');
return false;
}

// check for minimum length
if (document.form.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}

// check for spaces
if (document.form.myForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed."winking smiley;
return false;
}
else {
if (password != confirmpassword) {
alert ("You did not enter the same new password twice. Please re-enter your password."winking smiley;
return false;
} else {
alert('Nice job.');
return true;
}
}
}
// End -->

</script>


<style>

body{
width: 960px;
Margin-left:20px;
Margin-top: 20px;
}

form{
width: 400px;
height: 300px;
padding: 40px;
border: 1px solid #270644;
color: #fff;
Margin-left:600px;
Margin-top:200px;


-moz-border-radius: 20px;
-webkit-border-radius: 20px;

background: -moz-linear-gradient(19% 75% 90deg, #4E0085, #963AD6);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#963AD6), to(#4E0085));

/*** Shadow behind the box ***/
-moz-box-shadow:0px -5px 300px #270644;
-webkit-box-shadow:0px -5px 300px #270644;
}

label{
margin-left:70px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.5em;
}

input{
width: 230px;
background: #8a33c6;
padding: 10px;
margin-bottom: 10px;
margin-left:70px;
border-top: 1px solid #ad64e0;
border-left: 0px;
border-right: 0px;
border-bottom: 0px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.0em;



/*** Adding CSS3 ***/

/*** Transition Selectors - What properties to animate and how long ***/
-webkit-transition-property: -webkit-box-shadow, background;
-webkit-transition-duration: 0.25s;

/*** Adding a small shadow ***/
-moz-box-shadow: 0px 0px 2px #000;
-webkit-box-shadow: 0px 0px 2px #000;
}

input:hover{
-webkit-box-shadow: 0px 0px 4px #000;
background: #9d39e1;
}

input.submit{
width: 100px;
color: #fff;
text-transform: uppercase;
text-shadow: #000 1px 1px;
border-top: 1px solid #ad64e0;
margin-top: 10px;


/*** Adding CSS3 Gradients ***/
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#963AD6), to(#781bb9));
background: -moz-linear-gradient(19% 75% 90deg,#781bb9, #963AD6);
}

a{
width: 230px;
background: #8a33c6;
padding: 10px;
margin-bottom: 10px;
margin-left:62px;
border-top: 1px solid #ad64e0;
border-left: 0px;
border-right: 0px;
border-bottom: 0px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.0em;
text-decoration: none;
color: white;

/*** Adding CSS3 ***/

/*** Transition Selectors - What properties to animate and how long ***/
-webkit-transition-property: -webkit-box-shadow, background;
-webkit-transition-duration: 0.25s;

/*** Adding a small shadow ***/
-moz-box-shadow: 0px 0px 2px #000;
-webkit-box-shadow: 0px 0px 2px #000;

}

</style>
</head>

<body>
<?php

if (isset($_POST['do_register'])){

$link = mysql_connect('localhost', 'root', '??????????')or die('cannot connect to database'); //no password selected yet
mysql_select_db('register');

$username = mysql_real_escape_string($_POST['username']);
$password = sha1(mysql_real_escape_string($_POST['password']));
$confirmpassword = sha1(mysql_real_escape_string($_POST['confirmpassword']));
$query = "INSERT INTO `register`
(`username`, `password`, `confirmpassword`)
VALUES
('$username', '$password', '$confirmpassword')
";

$query = mysql_query($query) or die(mysql_error());



if($password != $confirmpassword){
echo ('<h3>You did not enter the same new password twice.');
return false;
} else {
echo('Passwords Match');
return true;
}
}


echo '<form id="myForm" method="post" id="commentForm" action="log_register.php?attempt" onsubmit="return validatePwd()">
<input type="hidden" name="do_register" /><br />
<label>Username:</label><br />
<input type="text" name="user" /><br />
<label>Password:</label><br />
<input type="password" name="password" /><br />
<label>Confirm:</label><br />
<input type="confirmpassword" name="confirmpassword" /><br />
<input type="submit" value="submit" name="submit" class="submit" />
<a href="log.php">Login</a>
</form>';

?>
</body>
</html>

Options: ReplyQuote
Re: No database selected
Posted by: RiggsFolly (---.as13285.net)
Date: June 20, 2013 05:11PM

Error is in the mysql_select_db() statement


$link = mysql_connect('localhost', 'root', '??????????')or die('cannot connect to database');

mysql_select_db('register', $link);

Options: ReplyQuote


Sorry, only registered users may post in this forum.