0

i am makin a simple account creation screen for my website and i have an error: Error: No database selected and i dont know why im getting this because i have used mysql_select_db(), heres my code:

<?php
			$con = mysql_connect("localhost");
			if (!$con)
			{
				echo "Could not connect:" . mysql_error() . "<br />";
				echo "If you are a visitor, please contact the site author <br />or one of the administrators.";
			}
			mysql_select_db("anzak_site", $con);
			$sql = "INSERT INTO user_accounts (first_name, last_name, age, username, password)" .
			"VALUES" .
			"(\"$_REQUEST[firstname]\",\"$_REQUEST[lastname]\",\"$_REQUEST[age]\",\"$_REQUEST[username]\",\"$_REQUEST[password]\")";
			if (!mysql_query($sql, $con))
			{
				echo "Error: " . mysql_error();	
			}
			else
			{
				echo "One(1) record added.";	
			}
			mysql_close($con);
		?>

any help would be appreciated :)

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by tomtetlaw
0

This is the line that is incorrect (or at least one of them).

$con = mysql_connect("localhost");

Replace it with something like the following but replace the username and password with the real username and real password:

$con = mysql_connect("localhost","username","password");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.