-1

I am getting the error above when I try to submit a form, I am new to php and first time trying this. I can not see what is wrong with the code. I have to complete this tasking for a prject at work

<?php

include "connection2.php";


//Getting the Values from the form
$Firstname = $_POST["Firstname"];
$Lastname = $_POST["Lastname"];
$DOB = $_POST["DOB"];
$Address = $_POST["Address"];
$Telephone_NO = $_POST["Telephone_No"];
$NOK = $_POST["NOK"];
$NOK_Address = $_POST["NOK_Address"];
$vetting_date = $_POST["vetting_date"];
$Clearance_Expiry = $_POST["Clearance_Expiry"];
$Current_Employer = $_POST["Current_Employer"];
$Resubmission = $_POST["Resubmission"];
$Number_of_Attempts = $_POST["Number_of_Attempts"];
$Qual1 = $_POST["Qual_1"];
$Date_Completed_1= $_POST["Date_Completed"];
$Expiry_Date_1 = $_POST["Run_out_date"];
$Qual2 = $_POST["Qual_2"];
$Date_completed_2 = $_POST["Date Completed"];
$expiry_date_2 = $_POST["Run_out_date"];
$Qualification3 = $_POST["Qual_3"];
$Date_completed_3 = $_POST["Date Completed"];
$Expiry_date_3 = $_POST["Run_out_date"];
$Qualification4 = $_POST["Qual_4"];
$Date_Completed_4 = $_POST["Date Completed"];
$Expiry_date_4 = $_POST["Run_out_date"];
$Qualification5 = $_POST["Qual_5"];
$Date_completed_5 = $_POST["Date Completed"];
$Expiry_Date_5 = $_POST["Run_out_date"];
$Qualifictation6 = $_POST["Qual_6"];
$Date_Completed_6 = $_POST["Date Completed"];
$Expiry_date_6 = $_POST["Run_out_date"];
$Qualification7 = $_POST["Qual_7"];
$Date_Completed_7 = $_POST["Date Completed"];
$Expiry_date_7 = $_POST["Run_out_date"];
$Qualification8 = $_POST["Qual_8"];
$Date_completed_8 = $_POST["Date Completed"];
$Expiry_date_8 = $_POST["Run_out_date"];
$Qualification9 = $_POST["Qual_9"];
$Date_completed_9 = $_POST["Date Completed"];
$Expiry_date_9 = $_POST["Run_out_date"];
$Qualification10 = $_POST["Qual_10"];
$Date_completed_10 = $_POST["Date Completed"];
$Expiry_date_10 = $_POST["Run_out_date"];



//inserting to the database
$sql = "INSERT INTO Applicant (Firstname) VALUES (`$Firstname`), (Lastname) VALUES (`$Lastname`), (Address) VALUES (`$Address`), (DOB) VALUES (`$DOB`), (Telephone_No) VALUES (`$Telephone_No`), (NOK) VALUES (`$NOK`), (NOK_Address) VALUES (`$NOK_Address`), (Vetting_Date) VALUES (`$vetting_date`), (Clearance_Expiry) VALUES (`$Clearance_Expiry`), (Current_Employer) VALUES (`$current_employer`), (Resubmission) VALUES (`$Resubmission`), (Number_of_Attempts) VALUES (`$Number_of_Attempts`)";
$sql = "INSERT INTO Qualifaction_Link (Date_Completed) VALUES (`$date_completed_1`), (Run_out_Date) VALUES (`$Expiry_date_1`), (Date_Completed) VALUES (`$date_completed_2`), (Run_out_Date) VALUES (`$Expiry_date_2`), (Date_Completed) VALUES (`$date_completed_3`), (Run_out_Date) VALUES (`$Expiry_date_3`), (Date_Completed) VALUES (`$date_completed_4`), (Run_out_Date) VALUES (`$Expiry_date_4`), (Date_Completed) VALUES (`$date_completed_5`), (Run_out_Date) VALUES (`$Expiry_date_5`), (Date_Completed) VALUES (`$date_completed_6`), (Run_out_Date) VALUES (`$Expiry_date_6`), (Date_Completed) VALUES (`$date_completed_7`), (Run_out_Date) VALUES (`$Expiry_date_7`), (Date_Completed) VALUES (`$date_completed_8`), (Run_out_Date) VALUES (`$Expiry_date_8`), (Date_Completed) VALUES (`$date_completed_9`), (Run_out_Date) VALUES (`$Expiry_date_9`), (Date_Completed) VALUES (`$date_completed_10`), (Run_out_Date) VALUES (`$Expiry_date_10`)";
$sql = "INSERT INTO Qualifaction (Qual_1) VALUES (`$qualification1`), (Qual_2) VALUES (`$Qualification2`), (Qual_3) VALUES (`$Qualification3`), (Qual_4) VALUES (`$Qualification4`), (Qual_5) VALUES (`$Qualification5`), (Qual_6) VALUES (`$Qualification6`), (Qual_7) VALUES (`$Qualification7`), (Qual_8) VALUES (`$Qualification8`), (Qual_9) VALUES (`$Qualification9`), (Qual_10) VALUES (`$Qualification10`)";

  if (!mysqli_query($sql)) {
  die (`Error: ` . mysqli_error());

  }

// if successfully insert data into database, displays message "Successful".
  if($result){
  echo "Successful";
  echo "<BR>";
  echo "<a href='index.php'>Back to Home page page</a>";
}

  else {
  echo "ERROR";
}
?> 
 //closing the connection
 mysqli_close()
 ?>

this is all of the code

here is the form code

Cyber Warfare

<header> 
    <h1 align="center"> Cyber Warfare Application Form </h1>
</header>

<center><img  src="cyberwarfareimage1.png" alt="Squadron logo" style="width:300px;height:300px" style="middle"> </center>

<body>
 <table border="1">
<tr>
  <td><a href="index.php"> Home Page </a>
  </table>
  <br>
  <br>
  <br>


    <form action=applicationform.php method="post"/>
            First name:<br>
            <input type="text" name="Firstname">
        <br>
        <br>
            Last Name:<br>
            <input type="text" name="Lastname">
        <br>
        <br>
            Date Of Birth YYYY/MM/DD:<br>
            <input type="Date" name="DOB">
        <br>
        <br>
            Address:<br>
            <input type="text" name="Address">
        <br>
        <br>
            Telephone Number:<br>
            <input type="text" name="Telephone_No">
        <br>
        <br>
            Next Of Kin:<br>
            <input type="text" name="NOK">
        <br>
        <br>
          Next Of Kin Address:<br>
            <input type="text" name="NOK_Address">
        <br>
        <br>
            Vetting Date YYYY/MM/DD:<br>
            <input type="date" name="vetting_date">
        <br>
        <br>
            Clearance Expiry YYYY/MM/DD:<br>
            <input type="date" name="Clearance_Expiry">
        <br>
        <br>
            Current Employer:<br>
            <input type="text" name="Current_Employer">
        <br>
        <br>
            Are you Resubmitting:<br>
            <input type="radio" name="Resubmission" value="Yes" >Yes
        <br>
        <input type="radio" name="Resubmission" value="No" checked>No
        <br>
        <br>
            If Yes How Many Previous Attempts:<br>
            <input type="number" name="Number_of_Attempts">
        <br>
        <br>
            Qualification 1:<br>
            <input type="text" name="Qual_1">
        <br>
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_1">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_1">
        <br>
        <br>
             Qualification 2 :<br>
            <input type="text" name="Qual_2">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_2">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_2">
        <br>
        <br>
             Qualification 3:<br>
            <input type="text" name="Qual_3">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_3">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_3">
        <br>
        <br>
             Qualification 4:<br>
            <input type="text" name="Qual_4">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_4">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_4">
        <br>
        <br>
            Qualification 5:<br>
            <input type="text" name="Qual_5">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_5">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_5">
        <br>
        <br>
            Qualification 6:<br>
            <input type="text" name="Qual_6">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_6">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_6">
        <br>
        <br>
            Qualification 7:<br>
            <input type="text" name="Qual_7">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_7">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_7">
        <br>
        <br>
            Qualification 8:<br>
            <input type="text" name="Qual_8">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_8">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_8">
        <br>
        <br>
            Qualification 9:<br>
            <input type="text" name="Qual_9">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_9">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_9">
        <br>
        <br>
            Qualification 10:<br>
            <input type="text" name="Qual_10">
        <br>
            Date Completed YYYY/MM/DD:<br>
            <input type="date" name="date_completed_10">
        <br>
            Expiry Date YYYY/MM/DD:<br>
            <input type="date" name="Run_out_date_10">
        <br>
        <textarea name="why"  rows="20" cols="40">Why do you want to join? In 150 words or less</textarea>
        <br><br>
        <input type="Submit" Value="Submit">
        <input type="reset" value="Reset">
    </form> 

thank you for the help

  • 2
    Can you post html of your form? – Sampath Liyanage Dec 11 '14 at 15:35
  • undefined index means it was not sent in the post array. My guess is your form does not set number of attempts until they fail at least once. So why not use a ternary to define that in the processing script? `$Number_of_Attempts = isset($_POST["Number_of_Attempts"]) ? $_POST["Number_of_Attempts"] : 1;` – Kai Qing Dec 11 '14 at 15:38
  • I'm new to all of this, I need to be user to be able to put a 0 or more in – Christopher Booth Dec 11 '14 at 15:40
  • Also, for the love of all things holy, please combine columns and values: `INSERT INTO \`Applicant\` (Firstname, Lastname, etc) VALUES ($firstname, $lastname, $etc)` – Kai Qing Dec 11 '14 at 15:40
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Matt Burrow Dec 11 '14 at 15:41
  • wont the last comment just hide the error messages, I need to see them so I can get the form fully working – Christopher Booth Dec 11 '14 at 15:47
  • I am also getting the same message for everything after number of attmepts – Christopher Booth Dec 11 '14 at 15:57

1 Answers1

0

In this case it means that the POST superglobal doesn't include this value, i.e. the form didn't include that value or the input field was set to "disabled".

Martin Müller
  • 2,565
  • 21
  • 32