Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
$name = $_GET['txtName'];
	$email = $_GET['txtEmail'];
	$phone = $_GET['txtPhone'];
	$message = $_GET['txtMessage'];
	
	$host = 'localhost';
	$user = 'root';
	$password = '07E41A0516';
	$dbSelect = 'gcmas';
	echo $dbc = mysqli_connect($host, $user, $password) or die('Error connecting to database server');
	
	echo $db = mysql_select_db($dbSelect) or die('Database Not Selected');
	
	echo $query = "INSERT INTO enquiryform (Name, EmailID, Phone, Message) VALUES ('$name', '$email', '$phone', '$message');";
	
	echo $result = mysql_query($query, $db) or die( 'Error queriying database'.mysql_error() );
	
	mysql_close();


I am getting 'Database Not Selected' error please help...

I tried a lot pages the code is the same but it's not working in my xampp server...
Posted
Comments
walterhevedeich 2-May-13 22:05pm
   
I think it has to do with your PHP version. Try using mysqli_select_db() and mysqli_query().

1 solution

I think it should be

PHP
echo $db = mysqli_select_db($dbSelect) or die('Database Not Selected');


you connected to the database using mysqli_connect so try selecting using mysqli_select_db too. and better still specify the database your and connecting to in the mysqli_select_db if you have more than one connected database

PHP
echo $db = mysqli_select_db($dbc, $dbSelect) or die('Database Not Selected');


and to remove the database selection part just use

PHP
echo $query = "INSERT INTO enquiryform.gcmas (Name, EmailID, Phone, Message) VALUES ('$name', '$email', '$phone', '$message');";


while you remove the mysql_select_db part
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900