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!!

<?php

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

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

if(isset($_POST['firstname']))
{
;
$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';
exit();
}
header('Location: .');
exit();
}

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

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"
	"http//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>Today&rsquo;s Date</title>
		<meta http-equiv="content-type"
			content="text/html; charset=utf-8"/>
	</head>
	<body>
<p>
	<form action="?" method="post">
	<div>
	<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>
</p>
<p>
	Please choose the relation to Chris Chinn<br />
	<select>
  	<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>
	</select>
	<p>
	<input type="submit" value="Register"/>
	</p>
	</form>
</p>
</body>
</html>

You forgot the = in

<input type=“text” id=“surname” name"surname" value=“Surname”>
viz
<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>
</select>

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?