I have a simple web form, which I want the user to fill out and when they click the submit button the information from the form should be inserted into the correct tables in the mySQL database for later use. I have a database called foundation_fitness
with a table called Client
.
The problem I am facing is this error message upon clicking submit:
Notice: Undefined index: exampleInputEmail1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 19
Notice: Undefined index: forname1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 20
Notice: Undefined index: surname1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 21
Notice: Undefined index: height1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 22
Notice: Undefined index: weight1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 23
Notice: Undefined index: bodyfat1 in C:\xampp\htdocs\ffitness\dist\new_client.php on line 24
Below is my code for new_client.php. EDIT: Changed Foundation_fitness to Client for the INSERT INTO
<?php
define('DB_NAME', 'foundation_fitness');
define('DB_USER', 'root');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$value2 = $_POST['exampleInputEmail1'];
$value3 = $_POST['forname1'];
$value4 = $_POST['surname1'];
$value5 = $_POST['height1'];
$value6 = $_POST['weight1'];
$value7 = $_POST['bodyfat1'];
$sql = "INSERT INTO client (Client_email, Client_forename, Client_surname, Height, Weight, Body_fat) VALUES ('$value2',
'$value3', '$value4', '$value5', '$value6')";
$result = mysql_query($sql);
mysql_close();
And the code for my html form is as follows: EDIT - Changed method
mistake and id
to name
<form action="new_client.php" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" name="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="form-group">
<label for="forename1">Forename</label>
<input type="text" class="form-control" name="forname1" placeholder="Enter First Name">
</div>
<div class="form-group">
<label for="surname1">Surname</label>
<input type="text" class="form-control" name="surname1" placeholder="Enter Surname">
</div>
<div class="form-group">
<label for="height1">Height (cm)</label>
<input type="text" class="form-control" name="height1" placeholder="Enter Height">
</div>
<div class="form-group">
<label for="weight1">Weight (kgs)</label>
<input type="text" class="form-control" name="weight1" placeholder="Enter Weight">
</div>
<div class="form-group">
<label for="bodyfat1">Body Fat %</label>
<input type="text" class="form-control" name="bodyfat1" placeholder="Enter Body Fat Percentage">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Any help with the error and getting the php script working would be much appreciated!
EDIT: I am now not getting the error message as I changed the method mistake and id to name in the HTML form. I am still not able to get the information into the table on the mySQL database even with the additional change of the table name which should have been client as I do not have a table called foundation_fitness that is the database name.