Solved

Moving the mysql connection to the next web page

Posted on 2003-12-03
5
300 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 200 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 200 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 200 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 50 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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