-1

this is the output

<?php

include_once('connection.php');



$StdID = $_REQUEST['txtID'];
$StdImage = $_REQUEST['txtImage'];
$FullName = $_REQUEST['txtFullname'];
$Address = $_REQUEST['txtAdd'];
$Bday = $_REQUEST['txtBday'];
$Grade = $_REQUEST['txtGrade'];
$Height = $_REQUEST['txtHeight'];
$Weight = $_REQUEST['txtWeight'];
$BloodPressure = $_REQUEST['txtBlood'];
$Gname = $_REQUEST['txtGname'];
$Contact = $_REQUEST['txtContact'];
$BCG = $_REQUEST['chkBCG'];
$Cardiac = $_REQUEST['chkCardiac'];
$Asthma1 = $_REQUEST['chkAsthma1'];
$Alcohol = $_REQUEST['chkAlcohol'];
$OPV1 = $_REQUEST['chkOpv1'];
$Thyroid = $_REQUEST['chkThyroid'];
$Chicken = $_REQUEST['chkChicken'];
$Tobacco = $_REQUEST['chkYosi'];
$OPV2 = $_REQUEST['chkOPV2'];
$Diabetes = $_REQUEST['chkDiabetes'];
$Measles = $_REQUEST['chkMeasles1'];
$Opv3 = $_REQUEST['chkOpv3'];
$Hypertension = $_REQUEST['chkHypertension'];
$Mumps = $_REQUEST['chkMumps1'];
$Food1 = $_REQUEST['txtFood1'];
$DPT1 = $_REQUEST['chkDpt1'];
$Tuberculosis = $_REQUEST['chkTuber'];
$Ulcer = $_REQUEST['chkUlcer'];
$Food2 = $_REQUEST['txtFood2'];
$DPT2 = $_REQUEST['chkdpt2'];
$Asthma2 = $_REQUEST['chkAsthma2'];
$Dengue = $_REQUEST['chkdengue'];
$Food3 = $_REQUEST['txtfood3'];
$Dpt3 = $_REQUEST['chkDpt3'];
$Kidney = $_REQUEST['chkKidney'];
$Head = $_REQUEST['chkHead'];
$Measles2 = $_REQUEST['chkMeasles2'];
$Cancer = $_REQUEST['chkCancer'];
$Std = $_REQUEST['chkstd'];
$Scar = $_REQUEST['chkScar'];
$Hepa = $_REQUEST['chkHepa'];
$Hypertension2 = $_REQUEST['chkHypertension2'];
$Mole = $_REQUEST['chkMole'];
$Std2 = $_REQUEST['chkStd2'];
$Kidney2 = $_REQUEST['chkKidney2'];
$Tattoo = $_REQUEST['chkTattoo'];
$OthersImmu = $_REQUEST['txtothersimmu'];
$Birthmark = $_REQUEST['txtBirthmark'];
$OthersImmu2 = $_REQUEST['txtothersimmu2'];
$OthersIll = $_REQUEST['txtothersill'];
$OthersImmu3 = $_REQUEST['txtothersimmu3'];
$OthersIll2 = $_REQUEST['txtothersill2'];
$Mens = $_REQUEST['txtmens'];



$sql = "INSERT INTO tbl_medics VALUES ('$StdID', '$StdImage', '$FullName', '$Address', '$Bday', '$Grade', '$Height', '$Weight', '$BloodPressure', '$Gname','$Contact', '$BCG', '$Cardiac', '$Asthma1', '$Alcohol', '$OPV1', '$Thyroid', '$Chicken','$Tobacco', '$OPV2', '$Diabetes', 'Measles', '$Opv3', '$Hypertension', '$Mumps', '$Food1', '$DPT1', '$Tuberculosis', '$Ulcer', '$Food2', '$DPT2', '$Asthma2', '$Dengue', '$Food3', '$Dpt3', '$Kidney', '$Head', '$Measles2', '$Cancer', '$Std', '$Scar', '$Hepa', '$Hypertension2', '$Mole', '$Std2', '$Kidney2', '$Tattoo', '$OthersImmu', '$Birthmark', '$OthersImmu2', '$OthersIll', '$OthersImmu3', '$OthersIll2', '$Mens')";

if ($conn->query($sql) === TRUE) {
    header("Location: MedicRecords.php?SuccessfullyAdded");
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

This is my Input

 <form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
 <?php $id = $_GET['id'];

  $sql = "SELECT * FROM tblstdpro where StdID = '$id'";



  $result = mysqli_query($conn,$sql);
  $count = 0;
  while($row = mysqli_fetch_array($result)){
    ?>
  <div class="box-body">
                <div class="form-group">

 <label><b>Student Image Location</b></label>
    <input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" type="readonly" readonly></br>


    <label><b>LRN</b></label>
    <input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required></br>

   <label><b>Full Name</b></label>
    <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtfullname" required></br>
    <label><b>Address</b></label></br>
    <input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required></br>
      <label><b>Birthday</b></label>
    <input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required></br>

  <label><b>Grade/ Course</b></label></br>
    <input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required></br>
        <label><b>Height</b></label>
    <input type="" class="form-control" placeholder="Enter Height" name="txtheight" required></br>
    <label><b>Weight</b></label>
    <input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required></br>
    <label><b>Blood Pressure</b></label>
    <input type="" class="form-control" placeholder="Enter BP" name="txtblood" required></br>


</br>
        <label><b><h3>*Person to be Notified in Case of Emergency</h3></b></label>
      </br>
          <label><b>Name:</b></label>
    <input type="text" class="form-control" value="<?php echo $row['Mother'];?>"  name="txtGname" required></br>
          <label><b>Contact No.</b></label>
    <input type="text" class="form-control" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"></br>
              <label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>

    <table class="table table-hover">
        <thead>
          <tr>
            <th>IMMUNIZATION</th>
            <th>FAMILY HISTORY</th>
            <th>PREVIOUS ILLNESS</th>
            <th>PERSONAL HISTORY</th>

          </tr>
        </thead>
        <tbody>
          <tr>





            <td><input type="checkbox" name="chkBCG" value="BCG"> &nbsp; BCG</td>
            <td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> &nbsp; Cardiac Disease</td>
            <td><input type="checkbox" name="chkAsthma1" value="Asthma"> &nbsp; Asthma</td>
    <td><input type="checkbox" name="" value="chkAlcohol"> &nbsp; Alcohol Use</td>
          </tr>
          <tr>





            <td><input type="checkbox" name="chkOpv1" value="OPV 1"> &nbsp; OPV 1</td>
            <td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> &nbsp; Thyroid Disease</td>
            <td><input type="checkbox" name="chkChicken" value="Chicken Pox"> &nbsp; Chicken Pox</td>
    <td><input type="checkbox" name="chkYosi" value="Tobacco Use"> &nbsp; Tobacco Use</td>
          </tr>
          <tr>





            <td><input type="checkbox" name="chkOpv2" value="OPV 2"> &nbsp; OPV 2</td>
            <td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> &nbsp; Diabetes Mellitus</td>
            <td><input type="checkbox" name="chkMeasles1" value="Measles"> &nbsp; Measles</td>
            <td>Allergy to Food, Drugs,Etc..</td>
          </tr>
         <tr>





            <td><input type="checkbox" name="chkOpv3" value="OPV 3"> &nbsp; OPV 3</td>
            <td><input type="checkbox" name="chkHypertension" value="Hypertension"> &nbsp; Hypertension</td>
            <td><input type="checkbox" name="chkMumps" value="Mumps"> &nbsp; Mumps</td>
    <td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
          </tr>
          <td><input type="checkbox" name="ChkDpt1" value="DPT1"> &nbsp; DPT 1</td>
            <td><input type="checkbox" name="chkTuber" value="Tuberculosis"> &nbsp; Tuberculosis</td>
            <td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> &nbsp; Peptic Ulcer</td>
    <td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
          </tr>
          <td><input type="checkbox" name="chkDpt2" value="DPT 2"> &nbsp; DPT 2</td>
            <td><input type="checkbox" name="chkAstma2" value="Asthma"> &nbsp; Asthma</td>
            <td><input type="checkbox" name="chkDengue" value="Dengue"> &nbsp; Dengue</td>
    <td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
          </tr>
          <tr>





            <td><input type="checkbox" name="chkDpt3" value="DPT 3"> &nbsp; DPT 3</td>
            <td><input type="checkbox" name="chkKidney" value="Kidney Disease"> &nbsp; Kidney Disease</td>
            <td><input type="checkbox" name="chkHead" value="Head Injury"> &nbsp; Head Injury</td>
            <td>Any Identification Mark:</td>
          </tr>
          <tr>





            <td><input type="checkbox" name="chkMeasles2" value="Measles"> &nbsp; Measles</td>
            <td><input type="checkbox" name="chkCancer" value="Cancer"> &nbsp; Cancer</td>
            <td><input type="checkbox" name="chkStd" value="STD"> &nbsp; STD</td>
            <td><input type="checkbox" name="chkScar" value="Scar"> &nbsp; 1. Scar</td>
          </tr>
          <tr>





            <td><input type="checkbox" name="chkHepa" value="HEPA-B"> &nbsp; HEPA-B</td>
            <td><input type="checkbox" name="chkSkin" value="Skin Disease"> &nbsp; Skin Disease</td>
            <td><input type="checkbox" name="chkHypertension2" value="Hypertension"> &nbsp; Hypertension</td>
            <td><input type="checkbox" name="chkMole" value="Mole"> &nbsp; 2. Mole</td>
          </tr>
          <tr>





            <td>Others:</td>
            <td><input type="checkbox" name="chkStd2" value="STD"> &nbsp; STD</td>
            <td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> &nbsp; Kidney Problem</td>
            <td><input type="checkbox" name="chkTattoo" value="Tattoo"> &nbsp; 3. Tattoo</td>
          </tr>
          <tr>





            <td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>

            <td></td>
            <td>Others:</td>
            <td><input type="checkbox" name="txtBirthmark" value="Birthmark"> &nbsp; 4. Birthmark</td>

          </tr>
          <tr>





            <td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>

            <td></td>
            <td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
            <td></td>

          </tr>
          <tr>





            <td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>

            <td></td>
            <td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
            <td></td>

          </tr>
        </tbody>
      </table>

      <label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
    <div class="form-group">
                <div class="input-group">
                  <div class="input-group-addon">
                    <i class="fa fa-calendar"></i>
                  </div>
                  <input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens" >
                </div>
                <!-- /.input group -->
              </div>
              <!-- /.form group -->
    <div class="clearfix">
          <button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button>
      <button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button>



</form></br></br>
    </div>
</form>

<?php
}
?>

Errors Says this

Notice: Undefined index: txtFullname in C:\wamp64\www\TestingThesis\AddMedicRecords.php on line 9

Error: INSERT INTO tbl_medics VALUES ('014-321', 'StdImage/014-321.jpg', '', '', '', '', '', '', '', 'Mommy','097576346', 'BCG', '', '', '', '', '', '','', '', '', 'Measles', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Kidney Disease', '', '', '', '', '', '', '', 'Mole', '', '', '', '', '', '', '', '', '', '')
Data truncated for column 'StdID' at row 1

How can this be done when there are so many uncheck it errors bet when i check it all it goes in, how can i put a default value if it is uncheck?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • you need to check the value is present and if not provide a default value.. if you dont check a checkbox the entire field is not present in the request... I may have misunderstood the question – Dale Feb 16 '18 at 16:46
  • 2
    The name of the input is `txtfullname`, but you're trying to get `$_POST['txtFullname']`. The uppercase `F` is wrong. – Barmar Feb 16 '18 at 16:48
  • How to ser a default value? – Byron Mataya Feb 17 '18 at 00:28
  • 1
    This code is massively insecure. Look up SQL injection. – ceejayoz Feb 17 '18 at 00:44
  • 1
    you're also inserting into a table without providing column names. Any changes to the table will immediately break the whole thing. – James Z Feb 17 '18 at 07:57

2 Answers2

0

The major issue is, when you are dealing with a checkbox, then you have to check whether it is checked or not like:

$value = '';    // Default value
if( isset($_REQUEST['checkbox_name']) )
{
    $value = $_REQUEST['checkbox_name'];
}

apart form that, your code is open to SQL Injections. And you are inserting data into table without providing column names. Any changes to the table will break the whole thing.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

Input name is wrong, change it to txtFullname instead of txtfullname.

<label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required>

Also i fixed all you invalid html tags:

<?php 
        $id = $_GET['id'];  
        $sql = "SELECT * FROM tblstdpro where StdID = '$id'";  
        $result = mysqli_query($conn,$sql);  $count = 0;  
        while($row = mysqli_fetch_array($result)){ ?>
    <form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
        <div class="box-body">
            <div class="form-group"> <label><b>Student Image Location</b></label> <input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" readonly><br>
                <label><b>LRN</b></label> <input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required><br>
                <label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required><br>
                <label><b>Address</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required><br>
                <label><b>Birthday</b></label> <input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required><br>
                <label><b>Grade/ Course</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required><br>
                <label><b>Height</b></label> <input type="" class="form-control" placeholder="Enter Height" name="txtheight" required><br>
                <label><b>Weight</b></label> <input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required><br>
                <label><b>Blood Pressure</b></label> <input type="" class="form-control" placeholder="Enter BP" name="txtblood" required><br> <br>
                <label><h3>*Person to be Notified in Case of Emergency</h3></label> <br>
                <label><b>Name:</b></label> <input type="text" class="form-control" value="<?php echo $row['Mother'];?>" name="txtGname" required><br>
                <label><b>Contact No.</b></label> <input type="text" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"><br>
                <label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>IMMUNIZATION</th>
                            <th>FAMILY HISTORY</th>
                            <th>PREVIOUS ILLNESS</th>
                            <th>PERSONAL HISTORY</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><input type="checkbox" name="chkBCG" value="BCG"> &nbsp; BCG</td>
                            <td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> &nbsp; Cardiac Disease</td>
                            <td><input type="checkbox" name="chkAsthma1" value="Asthma"> &nbsp; Asthma</td>
                            <td><input type="checkbox" name="" value="chkAlcohol"> &nbsp; Alcohol Use</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkOpv1" value="OPV 1"> &nbsp; OPV 1</td>
                            <td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> &nbsp; Thyroid Disease</td>
                            <td><input type="checkbox" name="chkChicken" value="Chicken Pox"> &nbsp; Chicken Pox</td>
                            <td><input type="checkbox" name="chkYosi" value="Tobacco Use"> &nbsp; Tobacco Use</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkOpv2" value="OPV 2"> &nbsp; OPV 2</td>
                            <td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> &nbsp; Diabetes Mellitus</td>
                            <td><input type="checkbox" name="chkMeasles1" value="Measles"> &nbsp; Measles</td>
                            <td>Allergy to Food, Drugs,Etc..</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkOpv3" value="OPV 3"> &nbsp; OPV 3</td>
                            <td><input type="checkbox" name="chkHypertension" value="Hypertension"> &nbsp; Hypertension</td>
                            <td><input type="checkbox" name="chkMumps" value="Mumps"> &nbsp; Mumps</td>
                            <td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
                        </tr>
                        <td><input type="checkbox" name="ChkDpt1" value="DPT1"> &nbsp; DPT 1</td>
                        <td><input type="checkbox" name="chkTuber" value="Tuberculosis"> &nbsp; Tuberculosis</td>
                        <td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> &nbsp; Peptic Ulcer</td>
                        <td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
                        </tr>
                        <td><input type="checkbox" name="chkDpt2" value="DPT 2"> &nbsp; DPT 2</td>
                        <td><input type="checkbox" name="chkAstma2" value="Asthma"> &nbsp; Asthma</td>
                        <td><input type="checkbox" name="chkDengue" value="Dengue"> &nbsp; Dengue</td>
                        <td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkDpt3" value="DPT 3"> &nbsp; DPT 3</td>
                            <td><input type="checkbox" name="chkKidney" value="Kidney Disease"> &nbsp; Kidney Disease</td>
                            <td><input type="checkbox" name="chkHead" value="Head Injury"> &nbsp; Head Injury</td>
                            <td>Any Identification Mark:</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkMeasles2" value="Measles"> &nbsp; Measles</td>
                            <td><input type="checkbox" name="chkCancer" value="Cancer"> &nbsp; Cancer</td>
                            <td><input type="checkbox" name="chkStd" value="STD"> &nbsp; STD</td>
                            <td><input type="checkbox" name="chkScar" value="Scar"> &nbsp; 1. Scar</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="chkHepa" value="HEPA-B"> &nbsp; HEPA-B</td>
                            <td><input type="checkbox" name="chkSkin" value="Skin Disease"> &nbsp; Skin Disease</td>
                            <td><input type="checkbox" name="chkHypertension2" value="Hypertension"> &nbsp; Hypertension</td>
                            <td><input type="checkbox" name="chkMole" value="Mole"> &nbsp; 2. Mole</td>
                        </tr>
                        <tr>
                            <td>Others:</td>
                            <td><input type="checkbox" name="chkStd2" value="STD"> &nbsp; STD</td>
                            <td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> &nbsp; Kidney Problem</td>
                            <td><input type="checkbox" name="chkTattoo" value="Tattoo"> &nbsp; 3. Tattoo</td>
                        </tr>
                        <tr>
                            <td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>
                            <td></td>
                            <td>Others:</td>
                            <td><input type="checkbox" name="txtBirthmark" value="Birthmark"> &nbsp; 4. Birthmark</td>
                        </tr>
                        <tr>
                            <td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>
                            <td></td>
                            <td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>
                            <td></td>
                            <td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
                            <td></td>
                        </tr>
                    </tbody>
                </table> <label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon"> <i class="fa fa-calendar"></i> </div> <input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens"> </div>
                    <!-- /.input group -->
                </div>
                <!-- /.form group -->
                <div class="clearfix"> <button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button> <button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button> <br><br> </div>
            </div>
        </div>
    </form>
    <?php }?>
Ghassan Elias
  • 2,213
  • 1
  • 14
  • 17