0

Hello I'm trying to send one variable with POST (Hello Angel). That is the code:

<form action="dos.php" method="post" name="compra">
  <input name="id_txt" type="hidden" value=<?php echo "Hello Angel" ?>/>
  <input type="submit" name="Send" value="Send" />
</form>

when in the other page show the variable, only shows up space (only Hello). That is the code:

<?php
  if (isset($_POST['id_txt']))
    echo $_POST['id_txt'] 
?>

So, how Can I show all?

2 Answers 2

5

Quote your value like this:

<input name="id_txt" type="hidden" value="<?php echo "Hello Angel"; ?>" />

When you don't put quotes around an HTML attribute value it only takes the first word as the value.

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

1 Comment

There is also a PHP function called htmlspecialchars() that will make sure that whatever you are echoing will work inside a HTML attribute even double quotes, just update your <?php ?> block to this: value="<?php echo htmlspecialchars("Hello \"Hacker\"<script>alert('Hi')</script>"); ?>"
4

You're missing the quotes around the input value

Change:

<input name="id_txt" type="hidden" value=<?php echo "Hello Angel" ?> />

To:

<input name="id_txt" type="hidden" value="<?php echo "Hello Angel" ?>" />

Comments

Your Answer

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