Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Moving the mysql connection to the next web page

Posted on 2003-12-03
5
Medium Priority
?
305 Views
Last Modified: 2006-11-17
I'm running linux/php/apache to manipulate a mysql data base.

The user enters a userId and password. I connect to the mysql data base using -

$linkId = mysql_connect( 'localhost', $userId, $password );

And I can do some queries, etc. (it's fine up to here).

Via a "submit" button, I go to another web page. I want to do more data base queries in this page.

Do I have to do another mysql_connect in the next web page?
Do I have to pass the userId and password to the next web page via hidden text fields?
Can I send the $linkId to the next web page? (equals "resource id #1" or some such. Doesn't work)


0
Comment
Question by:rfr1tz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 3

Accepted Solution

by:
ashoooo earned 800 total points
ID: 9868358
You can close the db connection and open a new one on every page... doesnt take a lot of resources.

As for the username and password, you can store them in session variables.
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 9868456
OK, so if I set a session variable on web page 1, can I reference and use it on web page 2.

I tried session variables. The web page where the variables were set seemed to remember the values, but the other web pages didn't know anything about these variables.

User error??
0
 
LVL 3

Assisted Solution

by:ashoooo
ashoooo earned 800 total points
ID: 9868715
You need to start the session on each page using the session_start() function.
0
 
LVL 3

Assisted Solution

by:ashoooo
ashoooo earned 800 total points
ID: 9868719
Dont forget to close the db connection on each page using mysql_close($linkId);
0
 
LVL 6

Assisted Solution

by:aolXFT
aolXFT earned 200 total points
ID: 9869035
normally you open a different mysql connection for each webpage you view.

If you want to reduce the connection overhead, and connect only once check out mysql_pconnect. mysql_pconnect only works if you are using an apache module.

You cannot maintain a connection between different CGI scripts.

www.php.net/mysql_pconnect
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question