-1

I am building an online system which a student can request for his or her transcript, I have been able to get hold of the information which will be passed to the database to fetch the result of that particular person using the superglobal $_REQUEST , my form action is Post and the student is to provide his Registration number eg: 300621713096, his first and last name eg Anthony Joshua and the Semesters he is requesting transcript eg: level 100 semester 1 . this is my code when I run it tells me data query failed , I want to know is

<?php
session_start();
require_once  'dbconnect.php';

$Reg_number = $_REQUEST['Reg_number'];
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$requestsem = $_REQUEST['requestsem'];
$Currentsem = $_REQUEST['Currentsem'];



   
  
?>

 <!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<html>
<head>
    <title>Transcript Portal</title>


    <link href="css/all.css" rel="stylesheet">
       <link rel="stylesheet" href="css/bootstrap.css">
       <link rel="stylesheet" href="css/bootstrap.min.css">
       



       <link type="text/css" href="css/style.css" rel="stylesheet" >
    
</head>
<body>


<table class="table table-bordered">
  <thead>
  <?Php
   if($Reg_number===$_REQUEST['Reg_number'] ){

    $sql="SELECT subject_code, subject_title, credit_point, ia, ea, total, grade, grade_point WHERE reg_num = '$Reg_number'";
   $result = mysqli_query( $connect , $sql);
   if(!$result){
     die("Data query failed");
   }
  }

   ?>
    <tr>
    <?Php
     echo 'Registration Number::', $Reg_number;
     echo 'Student Name::', $first_name  .  $last_name;
     echo 'PROGRAMME::', $Currentsem;
     echo 'SEMESTER::', $requestsem;
    ?>


    
      <th scope="col">SUBJECT</th>
      <th scope="col">SUBJECT TITLE </th>
      <th scope="col">CREDIT POINT</th>
      <th scope="col">IA</th>
      <th scope="col">EA</th>
      <th scope="col">TOTAL</th>
      <th scope="col">GRADE</th>
      <th scope="col">GRADE POINT</th>
    </tr>

   
   
  </thead>
  <tbody>
   <?php
       while(  $row=mysqli_fetch_assoc($result))
       {

       
   ?>
    <tr>
      <td><?php echo $row ['subject_code'];?></td>
      <td><?php echo $row ['subject_title'];?></td>
      <td><?php echo $row ['credit_point'];?></td>
      <td><?php echo $row ['ia'];?></td>
      <td><?php echo $row ['ea'];?></td>
      <td><?php echo $row ['total'];?></td>
      <td><?php echo $row ['grade_point'];?></td>
      
    </tr>
    <?php
    }
    ?>
    <tr>
      <td>kwame</td>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
      <td>@fat</td>
      <td>@fat</td>
      <td>@fat</td>
      <td>@fat</td>
    </tr>
    <tr>
      <td>kk</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
    </tr>
    <tr>
      <td>kk</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
    </tr>
    <tr>
      <td>kk</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
    </tr>
    <tr>
      <td>kk</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>Larry the Bird</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>








  <!-- jQuery library -->
  <script src="js/jquery-3.4.1.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

<?php
//
session_start();
require_once 'dbconnect.php';



?>

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<html>
<head>
    <title>Transcript Portal</title>


    <link href="css/all.css" rel="stylesheet">
       <link rel="stylesheet" href="css/bootstrap.css">
       <link rel="stylesheet" href="css/bootstrap.min.css">
       



       <link type="text/css" href="css/style.css" rel="stylesheet" >
    
</head>
<body>

<h1>Trust College</h1>
<h3>Provisional Transcript Portal</h3>
    <div class="wrapper">
     
        <form action="create.php" method="POST">
            <div class="form-group ">
                <label>Registration Number:</label>
                <input type="text" name="Reg_number" id="regnum" class="form-control" value="">
                <span class="help-block"></span>
            </div> 
             
            <div class="form-group">
                <label>First Name:</label>
                <input type="text" name="first_name" id="studentname" class="form-control" value="">
                <span class="help-block"></span>
                 
                
                <label>Last Name:</label>
                <input type="text" name="last_name" id="studentname" class="form-control" value="">
                <span class="help-block"></span> 
            </div>
            <div class="form-group">
                <label>Current Semester:</label>
                <select class="form-control" name="Currentsem">
                
             <option value="0" class="form-control">None</option>
             <option value="1"class="form-control">Level 100 Semester 1</option>
             <option value="2"class="form-control">Semester 2</option>
             <option value="3"class="form-control">Semester 3</option>
             <option value="4"class="form-control">Semester 4</option>
             <option value="5"class="form-control">Semester 5</option>
             <option value="6"class="form-control">Semester 6</option>
             <option value="7"class="form-control">Semester 7</option>
             <option value="8"class="form-control">Semester 8</option>
</select>
                
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <label>Requesting Semester:</label>
                <select class="form-control" name="requestsem">
                
             <option value="0" class="form-control">None</option>
             <option value="1"class="form-control">Semester 1</option>
             <option value="2"class="form-control">Semester 2</option>
             <option value="3"class="form-control">Semester 3</option>
             <option value="4"class="form-control">Semester 4</option>
             <option value="5"class="form-control">Semester 5</option>
             <option value="6"class="form-control">Semester 6</option>
             <option value="7"class="form-control">Semester 7</option>
             <option value="8"class="form-control">Semester 8</option>
</select>
                
                <span class="help-block"></span>
            </div>
            <div class="form-group">
                <input type="submit" class="btn btn-primary" name="submit" value="Submit">
            </div>
        </form>
    </div>    




   <!-- jQuery library -->
   <script src="js/jquery-3.4.1.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
 

<body>
</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    you forgot a `FROM` so the query should be `SELECT colums FROM table WHERE` you have `SELECT columns WHERE` – Sander Visser Oct 02 '19 at 16:46
  • 1
    Furthermore google for SQL Injection and prepared statements, cause your script is vunerable – Sander Visser Oct 02 '19 at 16:47
  • if you know you form using post method then why are you using REQUEST – devpro Oct 02 '19 at 16:49
  • `if($Reg_number===$_REQUEST['Reg_number'] ){` so u think anybody can change the REQUEST? – devpro Oct 02 '19 at 16:53
  • 1
    no need to use `bootstrap.js` when you have `bootstrap.min.js` minified file. – devpro Oct 02 '19 at 16:53
  • Possible duplicate of [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Oct 02 '19 at 17:03
  • @devpro thank you for the alert with regards to the REQUEST i used it because using the post was giving me erros in some way but i will use it . – Lexis smigz Oct 02 '19 at 19:01

1 Answers1

1

You didn't use "FROM TABLE_NAME" in your query. Also never use the client data request in your query! (SQL injection attack!)