how to post already posted variables!?!?

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

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Why not something like:

Code: Select all

if (isset($_POST['kataxorisi'])) {
    include 'kataxorisi.php';
} 
if (isset($_POST['emfanisi']))  {
    include 'emfanisi.php';
} 
if (isset($_POST['metavoli'])) {
    include 'metavoli.php';
} 
if (isset($_POST['diagrafi'])) {
    include 'diagrafi.php';
} 
if (isset($_POST['eggrafi'])) {
    include 'eggrafi.php';
}
instead of

Code: Select all

if (isset($_POST['kataxorisi'])) header("Refresh: 1; URL=http://localhost/kataxorisi.php"); 
if (isset($_POST['emfanisi'])) header("Refresh: 1; URL=http://localhost/emfanisi.php"); 
if (isset($_POST['metavoli'])) header("Refresh: 1; URL=http://localhost/metavoli.php"); 
if (isset($_POST['diagrafi'])) header("Refresh: 1; URL=http://localhost/diagrafi.php"); 
if (isset($_POST['eggrafi'])) header("Refresh: 1; URL=http://localhost/eggrafi.php");
You need to stop thinking about it being a case of these other scripts having access to the variables in post.php - it is more a case of you need to be able to access the code within files such as kataxorisi.php within post.php. including these files within post.php (using an if statement or switch statement to determine which is needed) makes more sense than redirecting from post.php to one of these files and then back again and any variables set in post.php before the other file is included will be available to the code in the included file.

Mac
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

stop beeing sarcastic and just help!! ok?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Sorry nik that was a bit harsh maybe. I am trying to help. I'm also busy working on a job for a client while I write this. Let me know how you get on.
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

<?php
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";

$onoma = $_POST['onoma'];
$eponymo = $_POST['eponymo'];
$til = $_POST['til'];
$email = $_POST['email'];
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

$sql=mysql_query("SELECT * FROM member");
while ($row = mysql_fetch_array($sql))
if (($_SERVER['PHP_AUTH_USER']==$row['user']) && ($_SERVER['PHP_AUTH_PW']==$row['pass']))
$i=1;
else
$i=0;

if ($i==0)
{
header('WWW-Authenticate: Basic realm="Ðïéüò åßóáé?"');
die ("<font size=5 color=Grey> Äåí åßóáé ìÝëïò ôçò ÁôæÝíôáò...ðñÝðåé ðñþôá íá ãñáöôåßò êáé ìåôÜ íá îáíÜñèåéò!!");
}
else
{
if (isset($_POST['kataxorisi'])) header("Location: kataxorisi.php?onoma=$onoma&eponymo=$eponymo&til=$til&email=$email");
if (isset($_POST['emfanisi'])) header("Location: emfanisi.php?onoma=$onoma&eponymo=$eponymo&til=$til&email=$email");
if (isset($_POST['metavoli'])) header("Location: metavoli.php?onoma=$onoma&eponymo=$eponymo&til=$til&email=$email");
if (isset($_POST['diagrafi'])) header("Location: diagrafi.php?onoma=$onoma&eponymo=$eponymo&til=$til&email=$email");
}
?>

do u see somethiong wrong in this code?
its my latest one !!! :)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You tell me.. Did you test it?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

Well actulally it works correclt escept some notices!!

Notice: Undefined variable: user in e:\web\kataxorisi.php on line 16

Notice: Undefined variable: user in e:\web\kataxorisi.php on line 18

Notice: Undefined variable: user in e:\web\kataxorisi.php on line 21
Η εγγραφή καταχωρήθηκε
Επαφές μέχρι στιγμής: 3
Notice: Undefined variable: user in e:\web\kataxorisi.php on line 24


it works but i get this notices too!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you ever try including instead of using header()? Then you wouldn't have to pass the variables via GET - you would just have access to them. For what you are trying to do include() is much more appropriate than header().

Mac
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

include what where???

in c d e f.php i had include 'b.php'

but it didnt get the vars so ti doent work!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you read the post I made which appears at the top of this page?

You have to include c, d, e, f etc in b. Basically use include() instead of header() - replace the one with the other.

Mac
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

yes i read it an i did it bu when i try to run it it says to me that b.php cannot be found. But if i remove the header statement and replace it by include how am i gonna redirect to the other scripts?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Nik wrote:yes i read it an i did it bu when i try to run it it says to me that b.php cannot be found.
What does your code look like when you replace the header calls with the include function? Isn't b.php the file you are including the other files into? Why would you include c into b and in c include b?

I am suggesting that you include all of the scripts and redirect to none - you can include multiple files into another file.

Mac
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

By the way, is there some reason you haven't mentioned why you have to use a header call - like checking a query string or something?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

<?php
ob_start(); error_reporting(E_ALL); $i=0;
echo "<body background=pics/anemos.bmp>";

$onoma = $_POST['onoma'];
$eponymo = $_POST['eponymo'];
$til = $_POST['til'];
$email = $_POST['email'];
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');

$sql=mysql_query("SELECT * FROM member");
while ($row = mysql_fetch_array($sql))
if (($_SERVER['PHP_AUTH_USER']==$row['user']) && ($_SERVER['PHP_AUTH_PW']==$row['pass']))
$i=1;
else
$i=0;

if ($i==0)
{
header('WWW-Authenticate: Basic realm="Ðïéüò åßóáé?"');
die ("<font size=5 color=Grey> Äåí åßóáé ìÝëïò ôçò ÁôæÝíôáò...ðñÝðåé ðñþôá íá ãñáöôåßò êáé ìåôÜ íá îáíÜñèåéò!!");
}
else
{
if (isset($_POST['kataxorisi'])) header("Location: kataxorisi.php ?onoma=$onoma &eponymo=$eponymo &til=$til &email=$email &user=$user");
if (isset($_POST['emfanisi'])) header("Location: emfanisi.php ?onoma=$onoma &eponymo=$eponymo &til=$til &email=$email &user=$user");
if (isset($_POST['metavoli'])) header("Location: metavoli.php ?onoma=$onoma &eponymo=$eponymo &til=$til &email=$email &user=$user");
if (isset($_POST['diagrafi'])) header("Location: diagrafi.php ?onoma=$onoma &eponymo=$eponymo &til=$til &email=$email &user=$user");
}
?>

Tell me pls
DO U SEE SOMETHING WRONMG IN THIS

REPLACE WHAT???

HEADER WITH INCLUDE

IF IAM GONNA DO THIS HOW ITS GONAN REDIRECT???????
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Sorry I don't think I can help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Nik wrote:REPLACE WHAT???

HEADER WITH INCLUDE
Yes as in the code I gave you above:

Code: Select all

if (isset($_POST['kataxorisi'])) header("Location: kataxorisi.php ?onoma=$onoma &eponymo=$eponymo &til=$til &email=$email &user=$user");
changed to

Code: Select all

if (isset($_POST['kataxorisi'])) include 'kataxorisi.php';
Nik wrote:IF IAM GONNA DO THIS HOW ITS GONAN REDIRECT???????
As McGruff asked - why do you need to redirect?

BTW, there's no need to shout at us, it's just as rude as being sarcastic. I am just as frustrated by the fact that you are having trouble understanding what I am saying as you are.

From the information that you have given, there appears to be no reason why you need to redirect instead of just including files - if there is a reason please tell us what it is. We can't help you if you just keep restating the same code without telling us why you desperately want to do something a particular way.

Mac
Post Reply