0

---THIS DOES NOT WORK-----

<?php
if($string != 55)
{
echo '<form action ="<?=$_SERVER[\'PHP_SELF\']?>". method = "POST"/>';
echo '<input type="submit" name="off" value="Turn OFF Grow Light"/>';
echo '</form>';
}
?>

It display's the submit button, everything LOOK's great, but when I press the button, it goes to some screwy blank page.
However, if I'm using raw html like below, everything works fine.
---THIS WORKS---

<form action ="<?=$_SERVER['PHP_SELF']?>". method = "POST"/> 
<input type="submit" name="off" value="Turn OFF Grow Light"/> 
</form>;
4
Contributors
7
Replies
24
Views
1 Year
Discussion Span
Last Post by Cody_4
0

As a C++ programmer and new to php , I just cannot figure out what I'm doing wrong here. I've wrapped the entire thing in single quotes, double quotes, used the escape character \' .. used brackets { } on the action variable. I know I'm missing something simple. I just can't see it. Anyone feel like pointing out where I'm going wrong? The button's show up, but when I press them it direct's to a blank page.

DOESN'T WORK

echo '<form action ="<?={$_SERVER[\'PHP_SELF\']}?>" method = "POST"/>
      <input type="submit" name="off" value="Turn OFF Grow Light"/>
      </form>';

      echo '<form action ="<?={$_SERVER[\'PHP_SELF\']}?>" method = "POST"/>
      <input type="submit" name="off" value="Turn OFF Grow Light"/>
      </form>';
0

I've spent an hour reading strings, I just cannot see what part here am I doing wrong?

0

OMG .... it was soo simple lolz.. This is why one shouldn't code whilst having 3 hour's sleep. :) Thanks allot for pointing me in the rigth direction :).

I changed the code to this and it works.
echo "<form action ='Auxiliary1.php' method = 'POST'/>";
echo "<input type='submit' name='off' value='Turn OFF Grow Light'/>";
echo "</form>";

However, I cannot get this to work. How do I pass in the $_SERVER[PHP_SELF];
THIS DOES NOT WORK
echo "<form action ='<?={$_SERVER[PHP_SELF]}?>' method = 'POST'/>";
echo "<input type='submit' name='off' value='Turn OFF Grow Light'/>";
echo "</form>";

0

Remove curly braces around $_server variable, its used when you want to embed variable in string.

echo "<form action ='<?=$_SERVER[PHP_SELF]?>' method = 'POST'/>";
echo "<input type='submit' name='off' value='Turn OFF Grow Light'/>";
echo "</form>";
0

Reverse:

  • remove the short PHP tags <?;
  • remove the shorthand = for echo as this string is already in a print construct;
  • leave the curly brackets in order to parse the variable.

So:

echo "<form action='{$_SESSION['PHP_SELF']}' method='post'>";

Better (IMHO):

$form = '<form action="%s" method="%s">';
echo sprintf($form, $_SESSION['PHP_SELF'], 'POST');

@Cody_4
See also: https://php.net/manual/en/language.basic-syntax.phpmode.php

Edited by cereal

0

Thanks everyone for sharing I really appreciate it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.