By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

POST, GET and variables ?

P: n/a
Hello,
As beginner, I'm a bit confused by passing 2 variables using a html-form
with method=POST. If passing one of them, it works ; if passing both
together, nope. At least when I reload the same page by using
$_SERVER["PHP_SELF"] in an included file (inc.php) it doesn't work.
Referring to another "page.php" is succesfull. Also passing both variables
with the GET-method works. Can somebody help me please ?
Thank you,
Dirk.
Feb 15 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
dirk kirjoitti:
Hello,
As beginner, I'm a bit confused by passing 2 variables using a html-form
with method=POST. If passing one of them, it works ; if passing both
together, nope. At least when I reload the same page by using
$_SERVER["PHP_SELF"] in an included file (inc.php) it doesn't work.
Referring to another "page.php" is succesfull. Also passing both variables
with the GET-method works. Can somebody help me please ?
Thank you,
Dirk.
Please post some code. The form itself would be quite helpful. What is
the output of <?php print_r($_POST); ?>

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 15 '07 #2

P: n/a
Kimmo Laine wrote:
>
Please post some code. The form itself would be quite helpful. What is
the output of <?php print_r($_POST); ?>
Thanks for your reply. If both input-text-fields were filled in, the
output of print_r($_POST) is : Array ( )
If only one input-text-field is filled in, output is : Array ( [email] =>
mail [pass] =) or Array ( [email] =[pass] =password )
Here is the code :

<?php
$dbh=mysql_connect("localhost","user","pass") or die("Can't connect to
db!");
mysql_select_db("calendar") or die("Can't select db!");
session_start();
if (!$_SESSION["Login"]) {
if ($_POST['email'] AND $_POST['pass']) {
$Email=$_POST['email'];
$Pass=$_POST['pass'];
$mydb=mysql_query("SELECT ID from admin WHERE Email='$Email'
and Pass= MD5('$Pass') LIMIT 1");
if ($data=mysql_fetch_array($mydb)) {
$_SESSION["Login"]=$data["ID"];
}
$me=$_SERVER['PHP_SELF'];
header("Location: $me");
exit;
}
print <<<EOL
<head>
<title>Admin Console</title>
</head>
<body>

<h1>admin system</h1>
<form action=
EOL;
echo $_SERVER["PHP_SELF"];
print <<<EOL
method=post>
<p>Email<input type=text name=email></p>
<pPass<input type=password name=pass></p>
<input type=submit>
</form></body></html>
EOL;
die();

}
?>
Feb 15 '07 #3

P: n/a
dirk kirjoitti:
Kimmo Laine wrote:
>Please post some code. The form itself would be quite helpful. What is
the output of <?php print_r($_POST); ?>
Thanks for your reply. If both input-text-fields were filled in, the
output of print_r($_POST) is : Array ( )
If only one input-text-field is filled in, output is : Array ( [email] =>
mail [pass] =) or Array ( [email] =[pass] =password )
In both cases it should also contain the submit button, I'm guessing it
defaults to "submit" ="submit" if no values are provided for name and
value.
Here is the code :

<?php
$dbh=mysql_connect("localhost","user","pass") or die("Can't connect to
db!");
mysql_select_db("calendar") or die("Can't select db!");
session_start();
if (!$_SESSION["Login"]) {
if ($_POST['email'] AND $_POST['pass']) {
$Email=$_POST['email'];
$Pass=$_POST['pass'];
$mydb=mysql_query("SELECT ID from admin WHERE Email='$Email'
and Pass= MD5('$Pass') LIMIT 1");
if ($data=mysql_fetch_array($mydb)) {
$_SESSION["Login"]=$data["ID"];
}
$me=$_SERVER['PHP_SELF'];
header("Location: $me");
exit;
Should the email and password match and the code reaches this point, the
post data is lost. Ie. if the login is successful, you'll never see the
result of the real print_r($_POST) because of the redirection. Humour me
and run the test case so that a) the login crendentials you input are
wrong so you don't log in and b) comment the header and exit lines so
that you are not redirected to another page after successfull login.
Then see the output.
}
print <<<EOL
<head>
<title>Admin Console</title>
</head>
<body>

<h1>admin system</h1>
<form action=
EOL;
echo $_SERVER["PHP_SELF"];
print <<<EOL
method=post>
<p>Email<input type=text name=email></p>
<pPass<input type=password name=pass></p>
<input type=submit>
</form></body></html>
EOL;
die();

}
?>
Of course it never hurts to eliminate all other possible causes for
failure, until you've narrowed it down to the real thing. Hence I
suggest you clean the code, insert the quotemarks in right places and so on.

Missing submit from $_POST is quite mysterious. The empty array() can be
explained if the page is redirected. The test case should be the kind
where there is absolutely nothing but a form and print_r to make sure
there isn't anything else causing the data to be lost.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Feb 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.