Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

If Statement not working as expected.

4:56 am on Apr 26, 2007 (gmt 0)

5+ Year Member

I am trying to get my error message to print if either the login is incorrect or the dropdown variable is "Unknown" I get no errors and I know that the variable is posting correctly. I think I'm missing something or put it in the wrong place. Any help would be appreciated.

if(($totalRows_rsLogin==0) ¦¦ ($HTTP_POST_VARS['dropdown']=="Unknown")){
$errorMessage = "Try Again.";

} else {
$HTTP_SESSION_VARS['postlogin'] = $HTTP_POST_VARS['username'];
header("Location: example.php");

5:18 am on Apr 26, 2007 (gmt 0)

5+ Year Member

I'm still learning too, so I could be wrong and maybe misunderstanding you, but I don't see where you are telling the script to print or echo $errorMessage.
5:23 am on Apr 26, 2007 (gmt 0)

5+ Year Member

Oh yea, that's a bad habit of mine...using the words "echo" and "print" in the wrong context.
In my script I call for an error message to display if the login fails. The error is actually echoed elsewhere ( not shown - above is just the section where I know the problem is) So your right the actual echo which looks like this:

<?php echo "$errorMessage";?>

is absent in the example I posted.

5:37 am on Apr 26, 2007 (gmt 0)

5+ Year Member

Are you using the variable $errorMessage somewhere else not show here?

If not, try this:

if(($totalRows_rsLogin==0) ($HTTP_POST_VARS['dropdown']=="Unknown")){
echo "Try Again.";
6:06 am on Apr 26, 2007 (gmt 0)

5+ Year Member

Thanks, Suzie...

I do have an echo for the error message it's just not shown here. For whatever reason the OR part of my script doesn't seem to work.

6:49 am on Apr 26, 2007 (gmt 0)

5+ Year Member

I got it working...
It turned out that I was indeed having trouble posting my variable correctly. What I ended up doing was creating a cookie via javascript instead of waiting for the PHP script to run its course and create one...That way I could call on the value immediately in the same script. Below is the drop down menu ( a hypothetical mock-up) that I put in the middle of my HTML form to generate a drop down list of my query result. I post it here in hopes that it will help someone trying to accomplish the same thing but also to illustrate where I echoed the javascript to create a cookie so that I could call on its value in the script at the top of this discussion.

<script language="php">
mysql_select_db($mydatabase, $myconn);
$query = "SELECT student FROM mydatabase WHERE dancepartner = '' ";
$result = mysql_query($query, $myconn);
if(mysql_num_rows($result)) {
while($row = mysql_fetch_row($result))
print("<option value=\"$row[0]\">$row[0]</option>");
} else {
print("<option value=\"\">No available dancepartners</option>");
echo "<script> document.cookie = 'mycookie=mycookievalue; path=/'</script>";

of course I modified this part in my orginal posted script to retrieve the cookie:

if(($totalRows_rsLogin==0) ¦¦ ($_COOKIE['mycookiej']=="mycookievalue")){