PDA

View Full Version : pass a variable to another page - PHP



imagined
March 9th, 2004, 12:34 PM
I have 2 PHP files:

send_data.php = has a form, and in the PHP section of the page I declared two variables that are used in the script. when user clicks SUBMIT it takes the user and the info INSIDE the form to receive_data.php

received_data.php = received the information that was submitted in the form inside send_data.php, but cannot use the variables that weren't declared in the form.

How can I declare variables in a file and then use the variables in another file. (The variables are not declared in the form)???


SEND_DATA.PHP

<?php
$edit_table=$_POST['edit_table'];

if ($edit_table == super)
{
echo("EDITING MESSAGE");
$ID = '11'; <<<<<< THIS IS THE VARIABLE I WANT TO USE IN RECEIVE_DATA.PHP

$sql_body = "SELECT body FROM $edit_table WHERE id = $ID";
$result_body = mysql_db_query('content', $sql_body);
$row_body = mysql_fetch_array($result_body);
$body = $row_body["body"];
?>

<form action="receive_data.php" method="post" name="edit_message">
<p>Edit:</p>
<textarea name="content" cols="70" rows="20" wrap>
<?php echo $row_body["body"]; ?>
</textarea>

<p>
<input type="submit" name="submitContent" value="SUBMIT" />
</p>
</form>

Jubba
March 9th, 2004, 12:45 PM
use either cookies or sessions... read more here:

Cookies: http://us3.php.net/manual/en/function.setcookie.php7

Sessions: http://us2.php.net/manual/en/ref.session.php

imagined
March 9th, 2004, 12:51 PM
What's better cookies or sessions?

imagined
March 9th, 2004, 01:08 PM
Can I just use in some way the POST method to achieve this? But without it being in the form. :tie:

hamza84
March 9th, 2004, 04:03 PM
<form action = "receive_data.php?ID=1">

in the receive_data.php, access ID like this:
$_GET['ID'];

Its much safer to use sessions as you're using the ID for a message to be edited.

Jubba
March 9th, 2004, 04:08 PM
yeah you're going to want to start learning how to use sessions and cookies. Its possible to do what you want without it, but its not the best, safest way to do it. Sessions are the way to go.

imagined
March 9th, 2004, 05:21 PM
THANKS!!! It works! YOU GUYS ROCK!!! :hr:

I'll look into cookies and sessions to improve the scripting,

Leo :tie: