Please help... Inside a frame my parameters dissappear!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattyb
Forum Newbie
Posts: 4
Joined: Mon Nov 22, 2004 10:05 pm

Please help... Inside a frame my parameters dissappear!

Post by mattyb »

I'm trying to use PHP inside a frame. The code for my script works perfectly on an open page but as soon as its called inside the frame I lose my paramaters that were passed from the previous pages form.

Here's my code:

<?php

$user_name = $_POST['user_name']; //set variables
$password = $_POST['password'];

$link = mysql_connect("localhost", "rt", "mb") //CHANGE ACCORDING TO PERSONAL DETAILS
or die("Could not connect to database");

mysql_select_db("db") //CHANGE TO YOUR PERSONAL DATABASE
or die("Could not select database");

$query = "SELECT * FROM users WHERE user_name = '$user_name' AND password = '$password'";
$result = mysql_query($query)
or die("Query failed");

$line = mysql_fetch_array($result);

if(mysql_num_rows($result)) {
$valid_user = 1;
}
else {
$valid_user = 0;
}

?>

This may be a really stupid problem as I'm quite new to PHP however I'm ready to tear my hair out... Any help would be appreciated.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

As far as I can understand the problem you are not allowing for the fact that the PHP for the frame creates a separate "page" and as such the "main" page does not know anything about the variables you set within the frame and vice versa. The normal way to deal with this is to use sessions and reload the main page. It should be noted that with CSS you could potentially avoid the use of frames and simplify the processing.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

or you have to use javascript to refrence the different parts of the frame and set the variables before the 'page' submits.

are you using a framset of iframes?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

a form can submit to only one page (well there is a workaround with JS if you look in this forum)

so you would have to store the submitted data in a session. then each page in the domain can access that data
mattyb
Forum Newbie
Posts: 4
Joined: Mon Nov 22, 2004 10:05 pm

Post by mattyb »

Thanks guys but it doesn't seem to be the parameters that are the problem more so that the page doesn't seem to be reading my php at all inside the frames... :cry: Im still working on it..
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

like said above,
as far as the browser is concerned, a frame is like opening a new browser window and going to the url for the frame

so this new window, cannot "read" the php from the prior page. in fact, it acts almost as if it knows nothing about it.

i think you do not understand this.

put it this way:

if you were to open a new browser window by hand, and paste the url to the frame into it, would you expect your script to work?
your answer should be no, and thats essentially whats happening.


a frame is a SEPERATE request, the browser just visually displays it as being part of the current one, but it is not.
mattyb
Forum Newbie
Posts: 4
Joined: Mon Nov 22, 2004 10:05 pm

Post by mattyb »

Thanks guys... Its all working now... If it were so easy
Post Reply