homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
If Statement not working as expected.
capulet_x




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

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($HTTP_POST_VARS['action']=="login"){
if(($totalRows_rsLogin==0) ¦¦ ($HTTP_POST_VARS['dropdown']=="Unknown")){
$errorMessage = "Try Again.";
mysql_free_result($rsLogin);

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

 

suzie250




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

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.

capulet_x




msg:3322106
 5:23 am on Apr 26, 2007 (gmt 0)

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.

suzie250




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

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

If not, try this:


if($HTTP_POST_VARS['action']=="login"){
if(($totalRows_rsLogin==0) ($HTTP_POST_VARS['dropdown']=="Unknown")){
echo "Try Again.";
mysql_free_result($rsLogin);

capulet_x




msg:3322136
 6:06 am on Apr 26, 2007 (gmt 0)

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.

capulet_x




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

Suzie,
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>";
}
</script>

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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved