Jump to content

'no database select'


luvburn

Recommended Posts

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...
Link to comment
https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90621
Share on other sites

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

[code]

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

?>
[/code]

The problem is, if the error 'no database select' happened, i couldn't view anything in my page. Kindly please help me. Tq.  :(
Link to comment
https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90799
Share on other sites

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 ...

[code]mysql_select_db($dbname)[/code]
Link to comment
https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90820
Share on other sites

ok then this is 'mysql_connect.php'

[code]
<?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";
?>
[/code]

But somehow i don' think the problem comes from this code. Eneway....i appreciate it if you could find the solution.
Link to comment
https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90855
Share on other sites

[quote][code]<?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";
?>[/code][/quote]

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
[code]
mysql_select_db($dbc) ;

[/code]

this will prevent no database selected errors, as you have told it which databse to connect to.
Link to comment
https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-91030
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.