Jump to content

No database selected error


madsovenielsen

Recommended Posts

Hello.I am trying to get this code to work.

<?php 		$host = "127.0.0.1";	$user = "root";	$password	= "*******";	$database	= "personal";		$connection = mysql_connect($host,$user,$password);		mysql_select_db($database, $con);		$sql = "SELECT * FROM files;";		$resultset = mysql_query($sql);				while($row = mysql_fetch_array($resultset))	{	echo $row['filename'] . "<br />";	}	echo mysql_error();mysql_close($con); ?>

mysql_error returns "No database selected"Although i have selected a database ??/mads

Link to comment
Share on other sites

mysql_error returns the most recent error. You should be checking the return value of all your mysql functions, starting from mysql_connect. You can't select a database if you don't have a connection, and you don't know yet if you have a connection.

Link to comment
Share on other sites

mysql_error returns the most recent error. You should be checking the return value of all your mysql functions, starting from mysql_connect. You can't select a database if you don't have a connection, and you don't know yet if you have a connection.
No difference. 127.0.0.1 and localhost gives the same error. "No database selected"/mads
Link to comment
Share on other sites

mysql_error returns the most recent error. You should be checking the return value of all your mysql functions, starting from mysql_connect. You can't select a database if you don't have a connection, and you don't know yet if you have a connection.
This code works perfectly on the same database and computer
<?php	$con = mysql_connect("127.0.0.1","root","*********");	  	  if (!$con)	  {		  die('Could not connect: ' . mysql_error());	  }	  mysql_select_db("users", $con);	  $result = mysql_query("SELECT * FROM active_users");	  while($row = mysql_fetch_array($result))	  {		  echo $row['id'] . $row['fname'] . "<br />";	  }	mysql_close($con);?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...