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.
Please help... Inside a frame my parameters dissappear!
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.
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.
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.