Variables not passing

Hi Again.

I’m having serious brain issues today!!! I’m trying to create 3 variables in and HTML form and then passthem to a php script which will write them into an MySQLi DB.

The first variable (firstname) passes no problem, however the other 2 variables (surname & relation) are being ignored.

Please see code below for php and HTML form.

Any ideas? as I said, my brain can’t seem to find this sort of error today!!


include $_SERVER['DOCUMENT_ROOT'] . '\\360feedback\\includes\\includes.php';

if (isset($_GET['newuser']))
include 'userform.html.php';
exit ();

$sql = 'INSERT INTO user SET
firstname = "' . $_POST['firstname'] . '",
surname = "' . $_POST['surname'] . '",
relation = "' . $_POST['relation'] . '"';

if(!mysqli_query($link, $sql))
$error = 'Error adding user:' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . '\\360feedback\\includes\\error.html.php';
header('Location: .');

$result = mysqli_query($link, 'SELECT * FROM user');
$error = 'Error fetching users: ' . mysqli_error($link);
include $_SERVER['DOCUMENT_ROOT'] . '\\360feedback\\includes\\error.html.php';

while ($row = mysqli_fetch_array($result))
$firstname[] = $row['firstname'];
$surname[] = $row['surname'];
$relation[] = $row['relation'];

include 'main.html.php';

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
		<title>Today&rsquo;s Date</title>
		<meta http-equiv="content-type"
			content="text/html; charset=utf-8"/>
	<form action="?" method="post">
	<label for="firstname">Please enter your name:</label><br />
	<input type="text" id="firstname" name="firstname" value="Firstname"></text>
	<input type="text" id="surname" name"surname" value="Surname"></text>
	Please choose the relation to Chris Chinn<br />
  	<option name = "relation" id="Peer" value="Peer">Peer</option>
  	<option name = "relation" id="Report"value="Report">Report</option>
  	<option name = "relation" id="Manager" value="Manager">Manager</option>
  	<option name = "relation" id="Self" value="Self">Self</option>
	<input type="submit" value="Register"/>

You forgot the = in

<input type=“text” id=“surname” name"surname" value=“Surname”>
<input type=“text” id=“surname” name=“surname” value=“Surname”>

And the name for a select is given in the <select> tag, not in the <option>s:

<select name="relation">
  	<option id="Peer" value="Peer">Peer</option>
  	<option id="Report"value="Report">Report</option>
  	<option id="Manager" value="Manager">Manager</option>
  	<option id="Self" value="Self">Self</option>

Also, you’d want to validate your html as it contains quite some errors. For example there is no such thing as </text>.

Did you put name=“relation” on the <select> tag instead of on the options, as I suggested.
Also, there should be a space between " and value in this line

<option id=“Report”<<put a space here>>value=“Report”>Report</option>

Using the W3C Markup Validation Service

Ok, that sorted the surname out.

But what about the ‘relation’ variable from the dropdown?

This is not passing either.

I copied the form tags from a website. How do you go about validating HTML tags?