0

Edit: After receiving some help, I edited some parts and here formlarigor2.php file and I got new error says 1)mysqli_stmt_bind_result() expects at least 2 parameters, 1 given.... 2)mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C.. I want to layout the page like given. layoutThat's why I used td> codes.. Any help? :`

<?php

    $conn = mysqli_connect("localhost","root","","son_fbe");
            if (mysqli_connect_error()) {

            echo "Failed to connect to MySQL: " . mysqli_connect_error();
                 exit();

        }


    $formid = isset($_GET['formid ']) ? $_GET['formid '] : ''; 
    if ($stmt = mysqli_prepare($conn, "SELECT * FROM derssaydirma WHERE formid = ?")) {

            mysqli_stmt_bind_param($stmt, "s", $formid );
            mysqli_stmt_execute($stmt);
            mysqli_stmt_bind_result($stmt);

    }



?>


 <!DOCTYPE html> 
     <html lang="en"> 
         <head> <title></title> </head>
        <body>  <table   align="center" bordercolor="#CCCCCC" border="1" >
      <?php

   $i=0;
   while($row = mysqli_fetch_array($stmt)) {
   if($i%2==0)
  $classname="even";
   else
  $classname="odd";
  ?>

 <tr class="<?php if(isset($classname)) echo $classname;?>">
  <td width="235">Form ID</td>
 <td width="299"><?php echo $row["formid"]; ?></td>
  </tr>

<tr class="<?php if(isset($classname)) echo $classname;?>">
<td>O_AdiSoyadi</td>
<td><?php echo $row["O_AdiSoyadi"]; ?></td>
</tr>

 <tr class="<?php if(isset($classname)) echo $classname;?>">
 <td>OgrenciNo</td>
<td><?php echo $row["OgrenciNo"]; ?></td>
</tr>
<tr class="<?php if(isset($classname)) echo $classname;?>">
 <td>Program_BaslanilanDonem</td>
<td><?php echo $row["Program_BaslanilanDonem"]; ?></td>
 </tr>
  //There are about 20 more like this code block( <tr></tr> <?php
 $i++;
 }
 ?>
</table>


`  

I have a table that consists of more than 25 columns. There is a page that shows forms waiting for approval. In that form, I do not show all columns instead I show only a few. I do that using PHP code. Here my code.

There is a part that says see all submitted forms and go to that forms. I am able to see all submitted ones however I could not see the specific row. For example, the table displays formid, name and etc, I want to get information of formid's 2. How can I do that? `

table

2 Answers 2

1

I am guessing that "Go to the Form" will be showing more information about the form in a different page layout.

So the element in the html should link to another php page that shows that form in detail. The link should take the id of the selected form.

<td width="174" class="centertext"><a href="formlarigor2.php/?formId=<?php echo $row["formid"]; ?>"> Go to the form</a></td>

And that linked php page will have a query that says something like:

$formId = $_GET['formId'];
$stmt = $mysqli->prepare("SELECT * FROM derssaydirma where id = ?");
$stmt->bind_param("i", $formId);
$stmt->execute();
$result = $stmt->get_result();

The using $result you can do the detail layout.

Note the use of prepared statements to avoid SQL injection.

Sign up to request clarification or add additional context in comments.

5 Comments

I added the formlarigor2.php file it directs the user to the different form that includes more information about the form. Can you check?. Also, what should I write instead of question mark?
$stmt->bind_param("s", $formId); what does s means here. What is the purpose of it?
The question mark is a parameter placeholder of the prepared statement. $stmt->bind_param("s", $formId) will replace the question mark with the $formId value. Sorry the "s" stands for string, perhaps the id is an int so it should be "i" (istead of "s"). Prepared statements are the only way to avoid sql injection. websitebeaver.com/…
What I understand from here is that you are saying I should put formid value such as 2 instead of a question mark, is that right? Since there will be more submitted forms on the table, I need to get each one. In this situation, What should I put instead of question mark. I am not good at English sorry for my grammar.
No. Just leave the question mark as it is. It is correct this way. Search for prepared statements with mysqli in php in google. You will understand.
1

Use the form id as parameter

<td width="174"  class="centertext"><a href="formlarigor2.php?formid=<?php echo $row["formid"]; ?>"> Go to the form</a></td> 

and in the formlarigor2.php you can get it as, where you put it at the start of php .

$formid = isset($_GET['formid ']) ? $_GET['formid '] : ''; 
if ($stmt = mysqli_prepare($conn, "SELECT * FROM derssaydirma WHERE formid = ?")) {

    /* bind parameters for markers */
    mysqli_stmt_bind_param($stmt, "s", $formid );

    /* execute query */
    mysqli_stmt_execute($stmt);

    mysqli_stmt_bind_result($stmt, $col1, $col2,$col3,$col4,$col5,$col6);
    while (mysqli_stmt_fetch($stmt)) {
      printf("%s %s\n", $col1, $col2);
    }
}

the fetch row part is usually in a while loop ti get multiple rows. but you have only one

7 Comments

Where specifically should I put the $formid = $_GET['formid']; in the file?
You should check it like any other parameter right at the beginning at least before you used it with $formid = isset($_GET['formid ']) ? $_GET['formid '] : ''; so that is always in a defined state and if it is empty redirekt to the start page
i added code for retrieving the one row of the tbale and use to show the name as example
I got these two errors; 1)Undefined variable: mysqli 2)Fatal error: Uncaught Error: Call to a member function prepare() on null in C
Ok i missed that you use procedural style and not the object orientated. try this one
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.