-4

I am trying to have a button that will check the status and respond according. So i tried using the if else statement to check the status. However its telling me that there is a Parse error: syntax error, unexpected 'if' (T_IF). Wonder if anyone what is causing the syntax error.

$list .= "<tr><td>".$userName."</td><td>".$usertype."</td><td>".$email."</td><td>". $address."</td><td>".$postalCode."</td><td>".$status."</td><td>

<form method='post'>"
    . if($status==1){ . 
    "<input type='hidden' name='ban' value='2'>
    <input type='submit' name='banned' value='Ban'>"
    .}else{ .
    "<input type='hidden' name='ban' value='1'>
    <input type='submit' name='uban' value='unBan'>"
    .}. "</td><td>
    <input type='hidden' name='name' value='$userName'>
    <input type='submit' name='remove' value='Remove'> 
    </form>
    </td></tr>";
4
  • 2
    Control statements cannot be part of expressions. This includes being concatenated with a string. Commented Jul 25, 2014 at 17:28
  • 1
    You can't put an if statement in the moddle of string concatenation Commented Jul 25, 2014 at 17:28
  • 1
    you should probably need to study php first. Commented Jul 25, 2014 at 17:28
  • You just not type <?php on top of your code, write HTML as is (with line feeds and tabulation) and temporarily switch to PHP mode to insert dynamic stuff. Commented Jul 25, 2014 at 17:37

1 Answer 1

1

This should work:

$list .= "<tr><td>".$userName."</td><td>".$usertype."</td><td>".$email."</td><td>". $address."</td><td>".$postalCode."</td><td>".$status."</td><td>

<form method='post'>"
    . ($status==1 ? 
    "<input type='hidden' name='ban' value='2'>
    <input type='submit' name='banned' value='Ban'>"
    :
    "<input type='hidden' name='ban' value='1'>
    <input type='submit' name='uban' value='unBan'>"
) . "</td><td>
<input type='hidden' name='name' value='$userName'>
<input type='submit' name='remove' value='Remove'> 
</form>
</td></tr>";

if is not an inline operator, it's a statement so you would have to call it separately. EDIT: if you want to still use if, here is the code:

$list .= "<tr><td>".$userName."</td><td>".$usertype."</td><td>".$email."</td><td>". $address."</td><td>".$postalCode."</td><td>".$status."</td><td>

<form method='post'>";
    if ($status==1)
      $list .= "<input type='hidden' name='ban' value='2'>
    <input type='submit' name='banned' value='Ban'>";
    else
      $list .= "<input type='hidden' name='ban' value='1'>
    <input type='submit' name='uban' value='unBan'>";
$list .= "</td><td>
<input type='hidden' name='name' value='$userName'>
<input type='submit' name='remove' value='Remove'> 
</form>
</td></tr>";
Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks for your help it works. I will read up more on it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.