I'm trying to create a form for a non-profit. I just can't seem to figure out what's wrong with this function I copied and pasted from W3Schools.
I've wrapped everything else in their own PHP tags and am still getting the error, so it's somewhere right here.
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
I'm sure you get this question just about every night but, I've been searching for hours and still can't figure it out. I wish there were a tool somewhere to find where you messed up.
EDIT
<?php
//define variables and set to empty values
$nameerr = $teamnameerr = $teamcaptainerr = $addresserr = $phoneerr = "";
$name = $teamname = $teamcaptain = $address = $phone = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameerr = "Name is required"; }
else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["teamname"])) {
$teamnameerr = "Teamname is required"; }
else {
$name = test_input($_POST["teamname"]);
}
if (empty($_POST["teamcaptain"])) {
$teamcaptainerr = "Name is required"; }
else {
$name = test_input($_POST["teamcaptain"]);
}
if (empty($_POST["address"])) {
$addresserr = "Adress is required"; }
else {
$name = test_input($_POST["address"]);
}
if (empty($_POST["phone"])) {
$phoneerr = "Phone number is required"; }
else {
$name = test_input($_POST["phone"]);
}?><?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>