select database error

A

Anonymous

Guest
I keep getting "Unable to select requested database." whywhywhywhywhyw!!!!!!??????

Code:
<?

$mysql_database="journal"; 
$mysql_username="root"; 
$mysql_password=""; 
$mysql_host="localhost";

$link = mysql_connect($mysql_host,$mysql_username,$mysql_password) or die ("unable to connect to SQL 

server"); 
mysql_select_db($mysql_database, $link) or die ("unable to select database"); 


{ 

	$query ="Insert Into entries (title, entry, date) Values ($title', '$entry', '$date')";
	$date = date('m d, Y');
        $db_query = mysql_query($query, $link) or die ("Unable to select requested database."); 

    } 

    mysql_close; 
  

?> 

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table align="center" border="1" bordercolor="#000000" cellspacing="0" cellpadding="3" 

bgcolor="#a1a1a1">
<tr><td><font face="Verdana" size="0" color="#000000">Title:</td><td><input type="text" name="title" 

maxlength="40"></td></tr>
<tr><td><font face="Verdana" size="0" color="#000000">Entry:</td><td><textarea name="entry" cols="100" 

rows="10"></textarea></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="update" value="Update"></td></tr>
</table>
</form>
 
Your connection code seems to be right, so:
Are you sure of this:
database -> journal
username, password and of course... your host -> localhost ??
 
yep all the info is right. it connects to the server otherwise i would get my die message unable to connect to sql server and it connects to the database otherwise i would get the select_db die error mesg. if i take the or die unable to select database then the html shows up but it doesnt sumbit the info into the database because...duh. i'm stumped.
 
i updated the code but i still get the same error

Code:
<?
	$mysql_database="journal"; 
	$mysql_username="root"; 
	$mysql_password=""; 
	$mysql_host="localhost"; 
		$link = mysql_connect($mysql_host,$mysql_username,$mysql_password) or die ("unable to 	

	connect to SQL server"); 
	mysql_select_db($mysql_database, $link) or die ("unable to select database"); 

if(isset($_POST['submit'])){ 
   $query ="Insert Into entries (id, title, entry, date) Values ('', '".$_POST['title']."', 

'".$_POST['entry'].", '".$_POST['date']."')"; 
   $date = date('m d, Y'); 
        $db_query = mysql_query($query, $link) or die ("Unable to select requested database."); 
     
?>
Update successful!
<?
}
else {
?>
<form action="<?$_SERVER['PHP_SELF']?>" method="post">
<table align="center" border="1" bordercolor="#000000" cellspacing="0" cellpadding="3" 

bgcolor="#a1a1a1">
<tr><td><font face="Verdana" size="0" color="#000000">Title:</td><td><input type="text" name="title" 

maxlength="40"></td></tr>
<tr><td><font face="Verdana" size="0" color="#000000">Entry:</td><td><textarea name="entry" cols="100" 

rows="10"></textarea></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="update" value="Update"></td></tr>
</table>
</form>
<?
}
?>
 
Yeh i know, but you´re using $link when selecting the database
PHP:
mysql_select_db($mysql_database, $link)
That´s why i´ve asked for it!
 
Please try this one:
PHP:
<?
$localhost ="localhost";
$dbuser="root";
$dbpass= "your_db_pass";
$dbname = "journal";

mysql_connect($localhost, $dbuser, $dbpass) or die 
(mysql_error());
@mysql_select_db ("$dbname") or die(mysql_error());
?>
 
well i get to the database now...with both connection scripts...but it isnt writing into the table.
 
We both ?? Just because you´re using $link here too:
Code:
$db_query = mysql_query($query, $link) or die ("Unable to select requested database.");

Anyway, was your query working before ??
 
well i got it to work. i should have just toyed with it before posting.

thanks for helping me.
 
Back
Top