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