Click to See Complete Forum and Search --> : session problem..Error 1046: No Database Selected.


beginnerz
04-28-2005, 04:31 AM
what is goin on with my session?

session.php

session_start();
$link = mysql_connect('localhost', 'root', '123456')
or die('Error ' . mysql_errno() . ': ' . mysql_error() . '.');

$db = mysql_select_db($_SESSION['xDb'], $link)
or die('Error ' . mysql_errno() . ': ' . mysql_error() . '.');

$_SESSION['xLink'] = $link;


and in each module will have one include(session.php);

but when i click on the module....it will shows Error 1046: No Database Selected....



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>web site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
include (session.php);
?>
<frameset rows="65,*" frameborder="NO" border="0" framespacing="0">
<frame src="top.html" name="topFrame" scrolling="NO" noresize >
<frame src="bottom.php" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>

scragar
04-28-2005, 04:33 AM
<?
include (session.php); //sessions must begin your page, or they won't work.
?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>web site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset rows="65,*" frameborder="NO" border="0" framespacing="0">
<frame src="top.html" name="topFrame" scrolling="NO" noresize >
<frame src="bottom.php" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>

Stephen Philbin
04-28-2005, 07:07 AM
The root of the problem is that you cannot serialise a database connection into a session for use on another page. If you know the real cause of the problem then hopefully you can figure out the solution that is best for your situation. ;)

beginnerz
04-28-2005, 09:46 PM
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\ehr\employee.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\ehr\lib\db\session.php on line 10

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\ehr\employee.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\ehr\lib\db\session.php on line 10

Notice: Undefined index: xDb in C:\Program Files\Apache Group\Apache2\htdocs\ehr\lib\db\ac.php on line 14
Error 1046: No Database Selected.

grailquester5
04-28-2005, 09:57 PM
beginnerz,

scragar showed you where to put the session_start() - all sessions MUST be initiated before any content is sent to the browser. See scragar's code for the proper placement of the session_start() call.

As for your database selection, the proper format for the database selection is

mysql_select_db(database_name);

I recommend using an include file for this and not putting it directly into code. Also, I noticed your connection is currently via "root." That's highly insecure and inadvisable. Create a special user for use in your web scripts with only the minimum permissions required to perform queries on the database. Using root access leaves your entire MySQL system wide open...