I've got a form asking for user input. The input should be a name which exists in my database.
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name" value="<?php echo $name;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
<input type="submit" name="login" value="Login">
</form>
I'm trying to first check user input, and then if the input is clean, send the user off to another site.
This is what I'm using to scrub the input:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
}
Then I would like to send to the next site after querying to my database and receiving an ID:
<form action = "http://website.com/~username/site.php" method="get">
Name: <input type="text" name="name"><br>
<Input type="submit">
</form>
How should I go about doing this?