Page 2 of 2

Posted: Thu Jan 15, 2004 10:12 am
by twigletmac
dimitris wrote:No Database?That means that require_once('connect.inc'); fails!
Seems like something's not right with that file - what's in it?

Mac

Posted: Thu Jan 15, 2004 10:36 am
by dimitris
This file is included inorder to make a connection with the database!It is the same that was used to authenticate the user in the login form!

Code: Select all

<?php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
function connect_db() {
    $db_server   =  'xxxxx';
    $db_user     =  'yyyyy';
    $db_password =  'zzzzzz';
    $db_database =  'db_name';
    $dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
    mysql_select_db($db_database);
    return $dbi;
}
if (!isset($dbi))  $dbi = connect_db();
?>

</body>
</html>
?>

Posted: Thu Jan 15, 2004 11:24 am
by llanitedave
dimitris wrote:This file is included inorder to make a connection with the database!It is the same that was used to authenticate the user in the login form!

Code: Select all

<?php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
function connect_db() {
    $db_server   =  'xxxxx';
    $db_user     =  'yyyyy';
    $db_password =  'zzzzzz';
    $db_database =  'db_name';
    $dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
    mysql_select_db($db_database);
    return $dbi;
}
if (!isset($dbi))  $dbi = connect_db();
?>

</body>
</html>
?>
Looks like you called "<?php" twice, without a "?>" tag between them.

Posted: Thu Jan 15, 2004 12:56 pm
by dimitris
Sorry that was my mistake enabling phpbb code!
Thats the right code which i use:
The index page sabotages itself at the next stage!
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body bgcolor="#FFFFFF" text="#000000">

Code: Select all

<?php
function connect_db() {
    $db_server   =  'xxxxx';
    $db_user     =  'yyyyyy';
    $db_password =  'zzzzzzz';
    $db_database =  'my_db';
    $dbi = mysql_connect($db_server, $db_user, $db_password) or die(mysql_error());
    mysql_select_db($db_database);
    return $dbi;
}
if (!isset($dbi))  $dbi = connect_db();

?>
</body>
</html>

Posted: Fri Jan 16, 2004 5:49 am
by twigletmac
It seems a bit strange that this has gone wrong - does changing:

Code: Select all

mysql_select_db($db_database);
to

Code: Select all

mysql_select_db($db_database) or die(mysql_error());
throw up a new error?

Mac

Posted: Fri Jan 16, 2004 7:40 am
by dimitris
I changed it but the same error returns!
I have also to add that pages' title changed to Untitled Document
In my opinion something wrong is going on with the headers!

That's the first lines of my code

Code: Select all

<?php
				session_start();
				header("Cache-control: private"); 
				session_register('logged_in'); $logged_in=0;
				session_register('session_id'); $session_id=0;
				error_reporting(E_ALL);
				if(isset($HTTP_POST_VARS['submit'])){
				if((strlen($HTTP_POST_VARS['username'])>0) AND (strlen($HTTP_POST_VARS['password'])>0)){ ....		
?>

Posted: Fri Jan 16, 2004 10:00 am
by twigletmac
Ah, session_register() is deprecated and doesn't play nicely with $_SESSION, try:

Code: Select all

<?php
session_start();
header("Cache-control: private");

$_SESSION['logged_in'] = 0;
$_SESSION['session_id'] = 0;

error_reporting(E_ALL);
if (isset($_POST['submit'])) {
	if ((strlen($_POST['username']) > 0) && (strlen($_POST['password']) > 0)) {
		....
?>

Posted: Fri Jan 16, 2004 11:03 am
by dimitris
Thanks a lot for the advise! I wasn't sure to use $_SESSION('x') whether session_register('x') but unfortunately the error continues!

Let me describe my page:
It is index.php with 4 php scripts which recall some records from some tables. There is a form which authenticates users. When a user submits the form he goes straight to the same page with the known results!

I will try to send the submition to another page (e.g. usercheck.php) and then with redirection back to index.php, with the suitable session variable.
I will try it and then inform you!

Of course the first error should also be resolved without this trick.