This is my PHP code that is used to connect my database and html form
<?php
$servername = "localhost";
$dbusername = "root";
$dbpassword = "";
$db_name = "message_blast";
#this code will provide connection to the database
$connect = new mysqli($servername, $dbusername, $dbpassword, $db_name);
if (!$connect){
die("connection failed: " . mysqli_connect_error());
}
$Lastname = $_POST['Lastname'];
$Firstname = $_POST['firstname'];
$Middlename = $_POST['middlename'];
$PhoneNumber = $_POST['phone_number'];
$Barangay = $_POST['barangay'];
$sql = "INSERT Into client (Lastname, Firstname, Middlename, PhoneNumber, Barangay) values ('$Lastname' , '$Firstname' , '$Middlename' , '$PhoneNumber' , '$Barangay' )";
if (mysqli_query($connect, $sql)){
echo "New record inserted successfully.";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($connect);
}
mysqli_close($connect);
?>
This is my html form
<form action="insert.php" method="POST" role="form" id="contactform" class="contactForm">
<div class="form-group">
<input type="text" name="firstname" class="form-control" id="firstname" placeholder="First Name" data-rule="minlen:4" required="required"/>
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" name="middlename" class="form-control" id="Middlename" placeholder="Middle Name" data-rule="minlen:4" required="required" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" name="Lastname" class="form-control" id="lastname" placeholder="Last Name" data-rule="minlen:4" required="required" />
<div class="validation"></div>
</div>
<div class="form-group">
<label for="barangay">Barangay:</label>
<select id="barangay" name="barangay" form="barangayform" length="16" required="required">
<option selected hidden> Choose Barangay </option>
<option value="volvo">Baikingun</option>
<option value="saab">Balulang</option>
<option value="opel">Bayabas</option>
<option value="audi">Bayanga</option>
<option value="audi">Besigan</option>
<option value="audi">Bonbon</option>
<option value="audi">Bulua</option>
<option value="audi">Canitoan</option>
<option value="audi">Carmen</option>
<option value="audi">Dansolihon</option>
<option value="audi">Iponan</option>
<option value="audi">Kauswagan</option>
<option value="audi">Lumbia</option>
<option value="audi">Mambua</option>
<option value="audi">Pagalungan</option>
<option value="audi">Pagatpat</option>
<option value="audi">Patag</option>
<option value="audi">Pigsag-an</option>
<option value="audi">San Simon</option>
<option value="audi">Taglimao</option>
<option value="audi">Tagpangi</option>
<option value="audi">Tignapoloan</option>
<option value="audi">Tuburan</option>
<option value="audi">Tumpangon</option>
<option value="audi">Agusan</option>
<option value="audi">Balubal</option>
<option value="audi">Bugo</option>
<option value="audi">Camaman-an</option>
<option value="audi">Consulacion</option>
<option value="audi">Cugman</option>
<option value="audi">Gusa</option>
<option value="audi">Indahag</option>
<option value="audi">Lapasan</option>
<option value="audi">Macabalan</option>
<option value="audi">Macasandig</option>
<option value="audi">Nazareth</option>
<option value="audi">Puerto</option>
<option value="audi">Puntod</option>
<option value="audi">Tablon</option>
<option value="audi">Poblacion</option>
</select>
<div class="validation"></div>
</div>
<div class="form-group">
<input type="tel" name="phone_number" class="form-control" id="phone number" maxlength="11" placeholder="Contact Number" data-rule="minlen:11" required="required" />
<div class="validation"></div>
</div>
<div class="text-center"><input type="submit" name="contactSubmit" id="contactSubmit" value="submit" ></div>
</form>