0

Im wondering from last few weeks as im beginner in php. how to retrieve the a particular row of data from mysql database and show into html table. First page passing s_no as a URL parameter id to the second page. So the second page needs to pick it up (i.e. id = $_GET['id']), then I use it in SQL query to add WHERE s_no = id . But its not working. Below is the coding a my second page.

 <?php

  $mysql_hostname = "localhost";
  $mysql_user = "root";
  $mysql_password ="";
  $mysql_database = "iaoform_db";

 // Create connection
 $conn = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database);
 // Check connection
 if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
 } 
 $id = $_GET['id']; //read id from get inputs
 $sqli = "SELECT s_no, title_pro, type, cycle, type_pro, thesis, year, 
 proposer, institute, 
 email,present,contact,abstract,status_ongoing,status_file,

 sch_request,no_night,no_night_impossible,just_request,instru1,mode_ob,
 brief_descrip,plan,hfosc_b,hfosc_n,hfosc_g,hfosc_s,hesp_r,hesp_o,
 tirspec_b,tirspec_n,tirspec_s,tirspec_c,tirspec_slits,obj_name,obj_ra,
 obj_dec,obj_epoch,obj_mag,obj_size,scient_just,date 

    FROM forms WHERE s_no = ? "; //add a where clause with place holder
    $stmt = $conn->prepare($sqli); 
    $stmt->bind_param('i', $id); //bind input parameters

    $stmt->execute(); 
    $stmt->store_result();
    /* Get the number of rows */
   $num_of_rows = $stmt->num_rows;

   /* Bind the result to $row variable */
   $stmt->bind_result($row);

    if($num_of_rows < 1){  //exit or send the result if number of rows is less than one 
        echo "Can't find any record!"; 
        mysqli_close($conn);    
        exit();}
      ?>


 <!---------------------------------------------------->
 <?php
    while ($stmt->fetch()){
      ?>

 <table class="tg" id="myModal">
   <tr>
     <th class="tg-9hbo">S.No</th>
     <th class="tg-yw4l" colspan="5"><?php echo $row["s_no"]; ?>   </th>
   </tr>
   <tr>
     <td class="tg-9hbo">Title of the proposal:</td>
     <td class="tg-yw4l" colspan="5"><?php echo $row["title_pro"]; ?>   
 </td>
   </tr>
       |
       |
       |
       |
       |
  <tr>
      <td class="tg-9hbo">Scientific Justification:</td>
     <td class="tg-yw4l" colspan="5"><?php echo $row["scient_just"]; ?>   
 </td>
   </tr>
   <tr>
     <td class="tg-9hbo">Submission date:</td>
     <td class="tg-yw4l" colspan="5"><?php echo $row["date"]; ?>   </td>
   </tr>


 </table>
 <?php

       $stmt->free_result();

    }
    mysqli_close($conn);
 ?>

Thank u so much. :)

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
explorer104
  • 47
  • 2
  • 10
  • [How to get mysqli error in different environments?](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments) – Masivuye Cokile Nov 29 '17 at 09:13
  • 1
    You need to `bind_result()` everything you selected I think – Masivuye Cokile Nov 29 '17 at 09:17
  • @MasivuyeCokile how will you explain with some example or with code please as I'm beginner in php .. thank u – explorer104 Nov 29 '17 at 09:21
  • ** But its not working**: what do you get? Errors in error_log, in the page, does your query work ok if you run it manually directly on the db? – Nic3500 Nov 29 '17 at 09:25
  • @Nic3500 Errors message is ::: `mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement` – explorer104 Nov 29 '17 at 09:27

0 Answers0