luvburn Posted September 12, 2006 Share Posted September 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/ Share on other sites More sharing options...
HuggieBear Posted September 12, 2006 Share Posted September 12, 2006 Show us the code for the page you get the error on.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90611 Share on other sites More sharing options...
paul2463 Posted September 12, 2006 Share Posted September 12, 2006 [quote]Why do i always get the error 'no database select' everytime i open a page that has sql statement in it.[/quote]does this sql statement say[code]mysql_select_db('name_of_database_to_select');[/code]?? Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90616 Share on other sites More sharing options...
gijew Posted September 12, 2006 Share Posted September 12, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90621 Share on other sites More sharing options...
luvburn Posted September 13, 2006 Author Share Posted September 13, 2006 This is my coding regarding the error. It's quite long but i just put the part where the php coding started.[code]<?phpinclude ('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. :( Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90799 Share on other sites More sharing options...
AndyB Posted September 13, 2006 Share Posted September 13, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90820 Share on other sites More sharing options...
luvburn Posted September 13, 2006 Author Share Posted September 13, 2006 ok then this is 'mysql_connect.php'[code]<?phpdefine("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. Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-90855 Share on other sites More sharing options...
paul2463 Posted September 13, 2006 Share Posted September 13, 2006 [quote][code]<?phpdefine("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 $dbcif 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. Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-91030 Share on other sites More sharing options...
luvburn Posted September 14, 2006 Author Share Posted September 14, 2006 Thank you...so far it works. Quote Link to comment https://forums.phpfreaks.com/topic/20539-no-database-select/#findComment-91502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.