Page 1 of 1

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

Posted: Mon Nov 22, 2004 11:45 pm
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.

Posted: Tue Nov 23, 2004 2:50 am
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.

Posted: Tue Nov 23, 2004 2:59 am
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?

Posted: Tue Nov 23, 2004 3:18 am
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

Posted: Tue Nov 23, 2004 6:39 pm
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..

Posted: Tue Nov 23, 2004 7:19 pm
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.

Posted: Thu Nov 25, 2004 9:14 pm
by mattyb
Thanks guys... Its all working now... If it were so easy