C.R.Vegelin wrote:
I have various PHP scripts that use the same database.
The startup script default.php sets the connection once for all the scripts. This connection is set in $_SESSION to make it a global variable for all scripts. When switching from page default to page faq, I get errors I can't explain. Any help is highly appreciated.
TIA, Cor
 default.php
----------------
<?php
session_start();
require("menu.php");

<snip>

faq.php
-----------
<?php require("menu.php");

The first two lines give it away ;)

You're missing a session_start().


--
Postgresql & php tutorials
http://www.designmagick.com/


Thanks Chris,

I included session_start(); as first line in faq.php, but now I get other warnings /errors:
Warning: mysqli_query() [function.mysqli-query]: Couldn't fetch mysqli
   in line "$result = mysqli_query($link, $sql);"
Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch mysqli
in line "if (!$result) { echo "Can't execute query ($sql): " . mysqli_error($link); exit; }

Actually - shoot me for not noticing this before.

You can't store a resource or connection in the session.

You have to recreate your connection in each page.

See http://php.net/session .

--
Postgresql & php tutorials
http://www.designmagick.com/


Hi Chris,

I recreated a new connection in faq.php and it's working now.
I had the impression that 1 connection could last during a user session,
but apparently a user session may need many connections.

Thanks again, Cor

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to