0

I have submitted some code to the redirected url and now trying to use this to echo some information out but can't figure out where I am going wrong.

I have the following code:

<?php $login_attempt = mysql_real_escape_string($_GET['login_attempt']);
    if ($login_attempt) == '1'{
    return 'failed';
    }
?>

all I want to do is if the url has $login_attempt=1 I want to return the message 'failed' to the page.

3
  • 1
    echo, not return and there's no reason to use mysql_real_escape_string() here Commented Dec 18, 2011 at 19:17
  • Why are you escaping that parameter if you are not using it as part of an SQL query? How is the parameter set? There are too many unknowns here. Commented Dec 18, 2011 at 19:17
  • im getting this error message on the page Parse error: syntax error, unexpected T_IS_EQUAL in /home/content/52/8417952/html/login.php on line 48 Commented Dec 18, 2011 at 19:18

6 Answers 6

2

There is no point of escaping anything if it doesn't enter anywhere important (like a database).

<?php 
    if ($_GET['login_attempt'] == '1') {
        echo 'failed';
    }
?>

Also, you have a problem in your if statement, that's corrected in the code above. Be sure to include all of the condition inside of parenthesis, and not just one side of the equality check.

Also, if you wish to display something on the screen, you should echo it, not return.

Sign up to request clarification or add additional context in comments.

1 Comment

echoing instead of returning isn't the only thing I changed in the code. Read the answer thoroughly to understand what I've done.
0

how about:

 if ($login_attempt == '1'){
    echo 'failed';
    }

Comments

0

Try this one. Your error in $login_attempt == '1':

<?php $login_attempt = mysql_real_escape_string($_GET['login_attempt']);
    if ($login_attempt == '1'){
        echo 'failed';
        return false;
    }
?>

Comments

0

As others already mentioned you have several problems but the syntax error comes from this:

if ($login_attempt) == '1'{

it should be

if ($login_attempt == '1') {

Comments

0

Dont u think if ($login_attempt) == '1' should be something like this ($login_attempt == '1') Sorry...many others also suggested this :P

Comments

0

At the first, I must tell you that you have a mistake in your IF condition. You typed == outside of (). In addition, you have to be aware of status of setting your variable through your URL. Check the code below. In this code, I made a function to check the status. Default status is true, and we will check it just for a negative condition. I hope it could be useful for you:

<?php
function check() {
   if (isset($_GET['login_attempt'])) {
      $login_attempt = mysql_real_escape_string($_GET['login_attempt']);
      if ($login_attempt == '1') {
         return false;
      } else {
         return true;
      }
   } else {
      return true;
   }
}
if (!check()) echo('Error Message');
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.