Thomas Lai
Thomas Lai

Reputation: 317

php redirection with form values

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!

Upvotes: 0

Views: 344

Answers (2)

GameBug
GameBug

Reputation: 136

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.

Upvotes: 0

sybear
sybear

Reputation: 7784

<?
    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()

Upvotes: 1

Related Questions