0

I am a beginner at php, but I want to write a script that will redirect me to an address with an attribute equal to the value of a form input. Is this the correct way?

index.html

<form action="process.php" method="post">
    <input type="text" name="name" placeholder="Your Name" />
    <input type="submit" />
</form>

and heres process.php:

<?
    header('Location: level1.html?name=' . $_POST['name']);
?>

For some reason, it doesn't work. Is there a better way? Thanks!

4
  • Please elaborate on "Doesn't work". Commented Feb 17, 2013 at 0:20
  • 1
    Ensure your header tag is above any code that has been outputted on the page (even a space before <? would cause an error). Commented Feb 17, 2013 at 0:22
  • thanks, this worked, I always skip a line before starting my code Commented Feb 17, 2013 at 0:25
  • Probably it is because your line is not above of all lines as @Titanium said. You even need to be sure that your document not using UTF char set with BOM. Commented Feb 17, 2013 at 0:25

2 Answers 2

1
<?
    header('Location: level1.html?name=' . $_POST['name']);
?>

change TO

<?php
    header('Location: level1.html?name=' . $_POST['name']);
?>

Edit:

Make sure you do not output anything before using header()

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

2 Comments

This will only help if OP has SHORT_OPEN_TAGS set to false.
That shouldn't make a difference.
0

I would suggest you to look into asynchronous post, it's faster and no need to deal with php header (especially it won't work if you have any markup language written before that), where you can simply use js/jQuery to forward with any values anywhere. Unless js is turned off.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.