Jump to content


Photo

'no database select'


  • Please log in to reply
8 replies to this topic

#1 luvburn

luvburn
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 12 September 2006 - 06:51 PM

hi...

Why do i always get the error 'no database select' everytime i open a page that has sql statement in it. I have to view other page that has no sql statement before i could open the page.

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 September 2006 - 06:54 PM

Show us the code for the page you get the error on.

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 12 September 2006 - 07:01 PM

Why do i always get the error 'no database select' everytime i open a page that has sql statement in it.


does this sql statement say

mysql_select_db('name_of_database_to_select');

??
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#4 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 12 September 2006 - 07:16 PM

Have you output to the browser which database you're trying to select?  I don't know your application layout but it seems like you might be including the files in the wrong order or perhaps not at all.  I run into problems often because I develop on a WinXP box and the server is Fedora Linux.  Sometimes I dont' pay attention to my capitalization which linux is strict about, windows isn't.

Just throwing that out there...
I'm considered good looking in some countries

#5 luvburn

luvburn
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 13 September 2006 - 12:42 AM

This is my coding regarding the error. It's quite long but i just put the part where the php coding started.


<?php
include ('mysql_connect.php');
include ('papar_fungsi.php');
//$currentPage = $_SERVER["PHP_SELF"];
 $age = $_GET["umur"];

session_name ('diagnos');
session_start();
if (!isset($_SESSION["diagnos"])) {
	$_SESSION["diagnos"] = NULL;
}

$maxRows_Recordset1 = 1;
$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

	if ( $age == 1 ){
	
	$query_Recordset1 = "SELECT * FROM simptom WHERE kategori='$tanda' AND bayi='y' ";
	}else {
	$query_Recordset1 = "SELECT * FROM simptom WHERE kategori = '$tanda'";
	}
	
	$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
	$Recordset1 = mysql_query($query_limit_Recordset1) or die(mysql_error());
	$row_Recordset1 = mysql_fetch_assoc($Recordset1);
	
	$id = $row_Recordset1['idsimptom'];
	
	if (isset($_GET['totalRows_Recordset1'])) {
	  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
	} else {
	  $all_Recordset1 = mysql_query($query_Recordset1);
	  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
	}

	$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
	
	$queryString_Recordset1 = "";
	if (!empty($_SERVER['QUERY_STRING'])) {
	  $params = explode("&", $_SERVER['QUERY_STRING']);
	  $newParams = array();
	  foreach ($params as $param) {

		if (stristr($param, "pageNum_Recordset1") == false && 
			stristr($param, "totalRows_Recordset1") == false) {
		  array_push($newParams, $param);
		}
	  }
	  if (count($newParams) != 0) {
		$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
	  }
	}
	$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
	
	$query= "SELECT * FROM jawapan WHERE kategori = '$tanda' AND idsimptom = '$id'";
	$result = mysql_db_query($dbc,$query);
	$myrow = mysql_fetch_array($result)
	
?>

The problem is, if the error 'no database select' happened, i couldn't view anything in my page. Kindly please help me. Tq.  :(

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 September 2006 - 01:47 AM

Actually, what we need to see is the content of mysql_connect.php (presumably where you make the database connection). Post all the code for that - putting **** for your username, password, etc.  'Somewhere' in that code there ought to be a line like ...

mysql_select_db($dbname)

Legend has it that reading the manual never killed anyone.
My site

#7 luvburn

luvburn
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 13 September 2006 - 03:53 AM

ok then this is 'mysql_connect.php'

<?php
define("DATABASE_HOST", "localhost");
define("DATABASE_USER", "root");
define("DATABASE_PASSWORD", "");


mysql_pconnect(DATABASE_HOST,DATABASE_USER, DATABASE_PASSWORD) or trigger_error(mysql_error(),E_USER_ERROR);;
$dbc = "xpert";
?>

But somehow i don' think the problem comes from this code. Eneway....i appreciate it if you could find the solution.

#8 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 13 September 2006 - 01:46 PM

<?php
define("DATABASE_HOST", "localhost");
define("DATABASE_USER", "root");
define("DATABASE_PASSWORD", "");


mysql_pconnect(DATABASE_HOST,DATABASE_USER, DATABASE_PASSWORD) or trigger_error(mysql_error(),E_USER_ERROR);;
$dbc = "xpert";
?>


looking at this code, can I assume that the database you wish to connect to is call 'xpert' ?
if that is the case then the above code would connect to your database host on a permanent basis and then assigns the string "xpert" to a variable called $dbc

if you wish to connect to your database called 'xpert' then you need the following code in there too
mysql_select_db($dbc) ;


this will prevent no database selected errors, as you have told it which databse to connect to.
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#9 luvburn

luvburn
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 September 2006 - 04:49 AM

Thank you...so far it works.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users