Error Undefined index barangay in C xampp htdocs TextBlast homepage insert php on line 22

0 votes

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>
Aug 14, 2020 in PHP by Regina
• 120 points

edited Aug 14, 2020 by Niroj 5,779 views

1 answer to this question.

0 votes

Hello @ Regina,

First checks whether a variable is set, which means that it has to be declared and is not NULL.

Try:

<?php

if (isset($_POST['Lastname'])) {
    $Lastname = $_POST['Lastname'];
}

if (isset($_POST['firstname'])) {
    $Firstname = $_POST['firstname'];}


If (isset ($_POST ['middlename'])) {

$Middlename = $_POST['middlename'];}


if (isset($_POST['phone_number'])) {
$PhoneNumber = $_POST['phone_number'];}


if (isset($_POST['barangay'])) {
$Barangay = $_POST['barangay'];}

?>

answered Aug 14, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

Fatal error: Cannot access empty property in C:\xampp\htdocs\MyTestPages\f.php on line 15

Hello @kartik, You access the property in the ...READ MORE

answered Oct 19, 2020 in PHP by Niroj
• 82,840 points
1,876 views
0 votes
1 answer

Error: Maximum execution time of 60 seconds exceeded in C:\xampp\phpmyadmin\libraries\dbi\mysql.dbi.lib.php on line 140

Hello @kartik, Go to: xampp\phpMyAdmin\libraries\config.default.php Look for : $cfg['ExecTimeLimit'] = 600; You ...READ MORE

answered Sep 1, 2020 in PHP by Niroj
• 82,840 points
14,589 views
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

How to send data to my database from html and css Contact Us Form?

Hello @Sign, It is simple to create contact ...READ MORE

answered Aug 4, 2020 in Database by Niroj
• 82,840 points
36,007 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
10,540 views
0 votes
1 answer
0 votes
1 answer

Notice: Undefined index: bid in C:\xampp\htdocs\userac\courier_management_system-master\courier_management_system-master\addstaff.php on line 130

Hello @saima , Before you extract values from $_POST ,$_SESSION, ...READ MORE

answered Sep 14, 2020 in PHP by Niroj
• 82,840 points
2,853 views
–1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP