I am trying to add data to the database only two records entered correctly (first name, member type), and the ID always be 0
here's the error:
Notice: Undefined index: memberid in C:\xampp\htdocs\...
Notice: Undefined index: lastname in C:\xampp\htdocs\..
Notice: Undefined index: phonenumber in C:\xampp\htdocs\...
Notice: Undefined index: email in C:\xampp\htdocs\...
Notice: Undefined index: username in C:\xampp\htdocs\...
Notice: Undefined index: password in C:\xampp\htdocs\...
Notice: Undefined index: department in C:\xampp\htdocs\...
Records added successfully.
What I have tried:
here's the code
For HTML
<pre><form action="test.php" method="post">
<div class="form-group">
<label for="element-1" class="control-label">First Name</label>
<input type="text" id="element-1" placeholder="Enter Your First Name Here" class="form-control" , name="firstname">
</div>
<div class="form-group">
<label for="element-2" class="control-label">Last Name</label>
<input type="text" id="element-2" placeholder="Enter Your Last Name Here" class="form-control",name="lastname">
</div>
<div class="form-group">
<label for="element-2" class="control-label">Member ID</label>
<input type="text" id="element-2" placeholder="Enter Your ID Here" class="form-control" ,name="member_id">
</div>
<div class="form-group">
<label for="element-2" class="control-label">User Name</label>
<input type="text" id="element-2" placeholder="Enter Your User Name Here" class="form-control",name="username">
</div>
<div class="form-group">
<label for="element-5" class="control-label"> Password</label>
<input type="password" id="element-5" placeholder="Enter Your Password Here" class="form-control",name="password">
</div>
<div class="form-group">
<label for="element-5" class="control-label">confirm Password</label>
<input type="password" id="element-5" placeholder="confirm Your Password Here" class="form-control",name="confirmpassword">
</div>
<div class="form-group">
<label for="element-5" class="control-label"> Email</label>
<input type="text" id="element-5" placeholder="Enter Your Email Here" class="form-control",name="email">
</div>
<div class="tyled-select blue semi-squar">
<label for="element-2" class="control-label">Member Type</label>
<select name="membertype">
<option value="" selected data-default>select member type</option>
<option value="professor">Professor</option>
<option value="assistent">Assistent</option>
<option value="student">Student</option>
</select>
</div>
<div class="form-group">
<label for="element-2" class="control-label">Phone Number</label>
<input type="text" id="element-2" placeholder="Enter Your Phone Number Here" class="form-control",name="phonenumber">
</div>
<div class="form-group">
<label for="element-2" class="control-label">department</label>
<input type="text" id="element-2" placeholder="Enter Your Department Here" class="form-control",name="department">
</div>
<button class="btn btn-primary" type="submit" name="submit">Add</button>
</form>
and here is my php code
if(isset($_POST['submit']))
{
$id = mysqli_real_escape_string($link, $_REQUEST['member_id']);
$first_name = mysqli_real_escape_string($link, $_REQUEST['firstname']);
$last_name = mysqli_real_escape_string($link, $_REQUEST['lastname']);
$phone= mysqli_real_escape_string($link,$_REQUEST['phonenumber']);
$email= mysqli_real_escape_string($link,$_REQUEST['email']);
$username= mysqli_real_escape_string($link,$_REQUEST['username']);
$password= mysqli_real_escape_string($link,$_REQUEST['password']);
$department= mysqli_real_escape_string($link,$_REQUEST['department']);
if (isset($_POST['membertype']) ){
$membertype= $_POST['membertype'];
}
$sql = "INSERT INTO `member` (`ID`, `first_name`, `last_name`, `member_type`, `password`, `email`, `phoneNo`, `department`, `user_name`)
VALUES ('$id', '$first_name', '$last_name','$membertype','$password','$email','$phone','$department','$username')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}