Hi There,

I've got a script and am trying to pass some variables to another script using the post method with the variables hidden. In the receiving script I am just trying to echo the variables to check the content has passed successfully for the time being, but instead of echoing the variable content it is just echoing the variable name.

I've fiddled with the syntax but can't get it to work.

Here's the part of the originating script that sets up the post:

	echo '<form action="test_verb.php" method="post">';
	echo '<input type="hidden" name="f_sng" value="$f_sng">';
	echo '<input type="submit" value="Click here to the verb!">';
	echo '</form>\n';

And here's my receiving script:

<?php

$f_sng = $_POST['f_sng'];

echo $f_sng;

?>

Perhaps someone can point out the error of my ways?
Thanks,
Tim.

    when you echo a variable in a string you need to encase it in {} curley brackets.

    echo '<form action="test_verb.php" method="post">'; 
        echo '<input type="hidden" name="f_sng" value="{$f_sng}">'; 
        echo '<input type="submit" value="Click here to the verb!">'; 
        echo '</form>\n'; 
    

      mmm I've tried that, but when I do that I still get the same problem... just now it displays {$f_sng} on the new page.

        You need to use singal speech marks or escape the double.

        This should work...

        echo '<form action='test_verb.php' method='post'>'; 
            echo '<input type='hidden' name='f_sng' value='{$f_sng}'>'; 
            echo '<input type='submit' value='Click here to the verb!'>'; 
            echo '</form>\n';

          That causes a parse error.

          I am interested as to why the {} isn't working either.

          <?php
              $f_sng = 'Hello!';
              echo '<input type="hidden" name="f_sng" value="'.$f_sng.'">'."\n"; // works
              echo "<input type=\"hidden\" name=\"f_sng\" value=\"$f_sng\">"."\n"; // works
              echo '<input type="hidden" name="f_sng" value="{$f_sng}">'."\n"; // does not work
              echo '<input type="hidden" name="f_sng" value="$f_sng">'."\n"; // does not work
              echo "<input type=\"hidden\" name=\"f_sng\" value=\"{$f_sng}\">"."\n"; // works    
          ?>

            Thanks for your help. I've got it working now.

            There seems to be so many ways of skinning a cat in php :-)

              I am interested as to why the {} isn't working either.

              Because it was used in a single quote delimited string, but variable interpolation (substitution) only happens with double quoted delimited strings (or with heredoc).

                Write a Reply...