0

This is my interface of PHP Software. I want to get the value of student class fee to fee input box after select class from select box.

Sample UI Image:
Sample UI Image

This is my code inside .php

    <select name="class_details2" style="" id="mySelect">
      <?php if (isset($_POST['student_name_submit'])) {
        $c1 = "SELECT * FROM student_class WHERE student_id = $data[0]";
        $result = $conn->query($c1);
    
        if ($result->num_rows > 0) {
          while ($row = mysqli_fetch_array($result)) {
    
            $sql2 = "SELECT * FROM `class` WHERE id='" . $row['class_id'] . "'";
            $result2 = $conn->query($sql2);
            $row2 = $result2->fetch_assoc();
    
    
            $sql3 = "SELECT * FROM `teachers` WHERE id='" . $row2['teacher'] . "'";
            $result3 = $conn->query($sql3);
            $row3 = $result3->fetch_assoc();
    
      ?>
            <option value="<?php echo $row["class_id"]; ?>" <?php if ($cls_id) {
                                                              echo "Selected";
                                                            } ?>>
              <?php echo $row2['class']; ?>- <?php echo $row3['name']; ?>- <?php echo $row2['fee']; ?>
    
            </option>
      <?php
          }
        } else {
          echo "0 results";
        }
      }
      ?>
    </select>
    
    </select>
    
    <div style="width: 15%;padding: 0px;"><input class="div_fee" required style="" maxlength="5" onkeypress="return isNumberKey(event)" name="fee" size="6" type="text"> </div>
Dharman
  • 26,923
  • 21
  • 73
  • 125
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Apr 10 '22 at 13:18

0 Answers0