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 :)

Recommended Answers

All 2 Replies

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");

That worked, thankyou :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.