By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

MySQL and PHP Session Variables

P: n/a
The following 3 mysql/php statements are used in my home page to
access my admin table:

$php_linkID = mysql_pconnect("localhost","user","pw");
mysql_select_db("test_db",$php_linkID);
$php_resultID = mysql_query("SELECT * FROM admin", $php_linkID);

On another web page I try to use another table in the same database
but I get an error on the if statement - I've saved the $php_linkID as
a session variable from the home page thinking I can just use it here
on a different web page - is this not possible?

$php_resultID = mysql_query("UPDATE controls SET screen_width =
frm_screen_width WHERE id = $php_session_member_name, $php_linkID);
if ($php_resultID != FALSE) <------ errors here
{
print "Database update error - Changes not made.";
}
else
{
print "My Controls successfully updated!";
}

Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


On 8-Aug-2003, Ralph Freshour <ra***@primemail.com> wrote:
The following 3 mysql/php statements are used in my home page to
access my admin table:

$php_linkID = mysql_pconnect("localhost","user","pw");
mysql_select_db("test_db",$php_linkID);
$php_resultID = mysql_query("SELECT * FROM admin", $php_linkID);

On another web page I try to use another table in the same database
but I get an error on the if statement - I've saved the $php_linkID as
a session variable from the home page thinking I can just use it here
on a different web page - is this not possible?

$php_resultID = mysql_query("UPDATE controls SET screen_width =
frm_screen_width WHERE id = $php_session_member_name, $php_linkID);
if ($php_resultID != FALSE) <------ errors here
{
print "Database update error - Changes not made.";
}
else
{
print "My Controls successfully updated!";
}


You really should add "or die(mysql_error())" to each of your mysql_query
statements.

I don't know if saving the link as a session variable will work, but it's a
really bad idea. You could end up with scads of open connections waiting for
users who will never return.

You SQL has several problems, like no closing ", missing 's around the
session id and frm_screen_width isn't a variable.
--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #2

P: n/a
Ralph Freshour <ra***@primemail.com> wrote in message news:<mo********************************@4ax.com>. ..
The following 3 mysql/php statements are used in my home page to
access my admin table:

$php_linkID = mysql_pconnect("localhost","user","pw");
mysql_select_db("test_db",$php_linkID);
$php_resultID = mysql_query("SELECT * FROM admin", $php_linkID);

On another web page I try to use another table in the same database
but I get an error on the if statement - I've saved the $php_linkID as
a session variable from the home page thinking I can just use it here
on a different web page - is this not possible?


Check the variable by echoing the content.... BTW, storing the
link id in session is not a good practice. Session may expire and will
throw errors.

---
Email: rrjanbiah-Y!com
Jul 16 '05 #3

P: n/a
On Sat, 09 Aug 2003 05:34:04 GMT, Ralph Freshour <ra***@primemail.com> wrote:
The following 3 mysql/php statements are used in my home page to
access my admin table:

$php_linkID = mysql_pconnect("localhost","user","pw");
mysql_select_db("test_db",$php_linkID);
$php_resultID = mysql_query("SELECT * FROM admin", $php_linkID);

On another web page I try to use another table in the same database
but I get an error on the if statement - I've saved the $php_linkID as
a session variable from the home page thinking I can just use it here
on a different web page - is this not possible?
No, you can't do that. A link ID is a resource handle, which is no longer
valid past the end of the script.

Besides, the whole idea of persistent connections is that opening up a
connection with mysql_pconnect on subsequence requests is cheap as it comes out
of a pool of already opened connections.
$php_resultID = mysql_query("UPDATE controls SET screen_width =
frm_screen_width WHERE id = $php_session_member_name, $php_linkID);
if ($php_resultID != FALSE) <------ errors here
{
print "Database update error - Changes not made.";


You've got the checking reversed as well; it's FALSE for an error.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.