473,408 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

POST variable not found

I have a validation form that lets you enter your ID and password. Then I
call the page again. This time the page script should check that it is a
"recall" and check the entered data with the database. With a match, set
three cookies (this doesn't work) and redirect to another page. With a
miss, see the cookies to "guest" values and redirect to a different page.

When I "echo" from within the code (for testing), it displays showing the
code was executed. When I don't, the code isn't executed at all. Here is
the code:

<?php
if ($_POST[postaction] == "validateuser")
{
// page redisplayed with results of this code
$user = "me";
$pwrd = "mypassword";
$cont = "localhost";
$name_db = "mokenabarber";
$name_table = "UserID";
// form variables
$id = $_POST["id"];
$pwd = $_POST["pwd"];
// set SQL session
$name_connect = mysql_connect($cont, $user, $pwrd) or die(mysql_error());
$db_connect = mysql_select_db($name_db, $name_connect) or
die(mysql_error());
// set SQL call
$sql_code = "SELECT Password, Level FROM $name_table ";
$sql_code .= "WHERE ID = '$id'";
// testing only
// echo $sql_code . "<br><br>";
// check SQL output
$sql_result = mysql_query($sql_code,$name_connect) or die(mysql_error());
$output = mysql_fetch_array($sql_result);
// store database variables
$pwdSQL = $output["Password"];
$lvlSQL = $output["Level"];
// testing only
// echo "sql pwd: '" . $pwdSQL . "'<br>sql lvl: '" . $lvlSQL . "'<br>rows:
'" . mysql_num_rows($sql_result) . "'<br>post pwd: '" . $pwd . "'<br>post
id: '" . $id . "'<br>";
// set cookie time limit - 180 days
$hold = 60 * 60 * 24 * 180;
if ($pwdSQL == $pwd)
{
// validated user - write cookie and continue
setcookie("user", "$id", $hold);
setcookie("level", "$lvlSQL", $hold);
setcookie("authorized", "yes", $hold);
header("Location: http://www.mokenahickorycreek.com/SQL_Staff.php");
exit;
}
else
{
setcookie("user", "guest", $hold);
setcookie("level", "0", $hold);
setcookie("authorized", "no", $hold);
header("Location: http://www.mokenahickorycreek.com/index.php");
exit;
}
}
?>

The goofy lack of whitespace is because the online manual says you can't
have it or cookies won't be set. But then their example has blank lines so
go figure. I've tried variations of using quotes and not using them, but
don't see any difference.

TIA, Lee
Jul 17 '05 #1
4 2296
>I have a validation form that lets you enter your ID and password. Then I
call the page again. This time the page script should check that it is a
"recall" and check the entered data with the database. With a match, set
three cookies (this doesn't work) and redirect to another page. With a
miss, see the cookies to "guest" values and redirect to a different page.

When I "echo" from within the code (for testing), it displays showing the
code was executed. When I don't, the code isn't executed at all. Here is
How do you know this? What is the result? A blank page?
Are you ABSOLUTELY SURE the password matches?
the code:

<?php
if ($_POST[postaction] == "validateuser")
{
// page redisplayed with results of this code
$user = "me";
$pwrd = "mypassword";
$cont = "localhost";
$name_db = "mokenabarber";
$name_table = "UserID";
// form variables
$id = $_POST["id"];
$pwd = $_POST["pwd"];
// set SQL session
$name_connect = mysql_connect($cont, $user, $pwrd) or die(mysql_error());
$db_connect = mysql_select_db($name_db, $name_connect) or
die(mysql_error());
// set SQL call
$sql_code = "SELECT Password, Level FROM $name_table ";
$sql_code .= "WHERE ID = '$id'";
// testing only
// echo $sql_code . "<br><br>";
// check SQL output
$sql_result = mysql_query($sql_code,$name_connect) or die(mysql_error());
$output = mysql_fetch_array($sql_result);
// store database variables
$pwdSQL = $output["Password"];
$lvlSQL = $output["Level"];
// testing only
// echo "sql pwd: '" . $pwdSQL . "'<br>sql lvl: '" . $lvlSQL . "'<br>rows:
'" . mysql_num_rows($sql_result) . "'<br>post pwd: '" . $pwd . "'<br>post
id: '" . $id . "'<br>";
// set cookie time limit - 180 days
$hold = 60 * 60 * 24 * 180;
if ($pwdSQL == $pwd)
{
// validated user - write cookie and continue
setcookie("user", "$id", $hold);
setcookie("level", "$lvlSQL", $hold);
setcookie("authorized", "yes", $hold);
header("Location: http://www.mokenahickorycreek.com/SQL_Staff.php");
exit;
}
else
{
setcookie("user", "guest", $hold);
setcookie("level", "0", $hold);
setcookie("authorized", "no", $hold);
header("Location: http://www.mokenahickorycreek.com/index.php");
exit;
}
}
?>

The goofy lack of whitespace is because the online manual says you can't
have it or cookies won't be set.
You may not output anything but headers before the setcookie() and
header() calls. This particularly includes whitespace OUTSIDE the
<? ?>. Whitespace inside <? ?> is OK. Your commented-out echo
statements will screw up the cookies if they are activated, as will
the die() calls.
But then their example has blank lines so
go figure. I've tried variations of using quotes and not using them, but
don't see any difference.


Gordon L. Burditt
Jul 17 '05 #2
The echo shows both the form entered password and the database one. I put
them in quotes so I can see if there is any trailing blanks or non-print
characters and they look the same. What I get is the page redisplaying
itself. For some reason I don't understand, the post action doesn't seem to
happen and the test against the POST variable always fails. When it did
work was when I uncommented the testing echo. Then that test does work (or
you wouldn't be able to see the echo which is inside of the POST if
condition), but I don't know why.

Doesn't seem logical that the line 2 test works when there is an echo on
line 29 and doesn't if there isn't. No wonder my hair is white.

Any ideas will be greatly appreciated.

Lee
Jul 17 '05 #3
Lee David wrote:
The echo shows both the form entered password and the database one. I put
them in quotes so I can see if there is any trailing blanks or
non-print characters and they look the same. What I get is the page
redisplaying itself. For some reason I don't understand, the post
action doesn't seem to happen and the test against the POST variable
always fails. When it did work was when I uncommented the testing
echo. Then that test does work (or you wouldn't be able to see the
echo which is inside of the POST if condition), but I don't know why.

Doesn't seem logical that the line 2 test works when there is an echo
on line 29 and doesn't if there isn't. No wonder my hair is white.

Any ideas will be greatly appreciated.

Lee


Try this, to see what's going on:

remove the redirects, and add some code at the bottom to output all of the
variables you're testing. Just simple <? echo
"variable_name='$variable'<br>"; ?> statements, listing all the variables.
At least that way you'll see what you're ending up with.

--
Tony Garcia
http://www.dslextreme.com/~tony23/
Jul 17 '05 #4
Thanks for the post. If you look at the code, you will see that I thought
like you do and have various "testing" code (commented out when it runs)
that do what you suggest - listing variables and values.

The good news is I found the problem and it was the idiot programmer, me,
that forgot to add in the current date to the additional time to keep the
cookie. It wasn't being written out due to being expired.

Now my new problem is a return to a prior one - including code within the
page. On the mainframe we would call it preprocessor code. Here I call it
a PITA. <g>

Lee

"Tony" <to*******@dslextreme.com.spam> wrote in message
news:11************@corp.supernews.com...
Lee David wrote:
The echo shows both the form entered password and the database one. I put
them in quotes so I can see if there is any trailing blanks or
non-print characters and they look the same. What I get is the page
redisplaying itself. For some reason I don't understand, the post
action doesn't seem to happen and the test against the POST variable
always fails. When it did work was when I uncommented the testing
echo. Then that test does work (or you wouldn't be able to see the
echo which is inside of the POST if condition), but I don't know why.

Doesn't seem logical that the line 2 test works when there is an echo
on line 29 and doesn't if there isn't. No wonder my hair is white.

Any ideas will be greatly appreciated.

Lee


Try this, to see what's going on:

remove the redirects, and add some code at the bottom to output all of the
variables you're testing. Just simple <? echo
"variable_name='$variable'<br>"; ?> statements, listing all the variables.
At least that way you'll see what you're ending up with.

--
Tony Garcia
http://www.dslextreme.com/~tony23/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Google Mike | last post by:
I have RH9 Linux with the versions of Apache and PHP that came with it. The PHP is version 4.2.2 on the CD, I believe. Apache, I think, is version 2.0. I found I can do some regular PHP stuff...
8
by: Tony | last post by:
I'm working with someone on a PHP project. The other person is doing testing of scripts on their personal machine using Apache as a web server. The production server and the one I'm using are both...
10
by: Dan Weeb | last post by:
Hi Guys, I really am a novice and found a script on webmonkey. Basically all I want to do is to add records to my database. In my database I have a table called research_main with the fields...
3
by: Dave | last post by:
I am farly new to java and am interested in how to cover a 'range'. ie. if variable != cheers, Dave --- Outgoing mail is certified Virus Free.
9
by: james | last post by:
please excuse my ignorance of Python. i know enough to be dangerous (was able however to make Freevo support my FM tuner with a little hacking). Ultimate goal: read N bytes from PATTERN on page...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
6
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process...
18
by: Patrick Wood | last post by:
I found a problem with C# and post increments. I was going through some source code in c++ and found someone did a post increment: int x=0; for(int i=0; i<10; i++) { x = x++; }
6
by: fjm | last post by:
Hi All, This is a very basic thing but I can't get it quite right. I have 2 pages. The first page is a login page. The second page checks the password and username and redirects back to the first...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.