-1

I have a MySql database which has users and each user gets a grade see below:

ID   NAME   GRADE
1    Sean    10
2    Sarah   15
3    Seo     12
4    Ste     32

Basically, I want to be able to dynamically print out whats stored in the database and add a text input box which enables me to enter in grades which are stored for each individual person. I then want this grade to be stored in the database for the user. Is this possible? I have code which prints out the users but doesn't include a text box

<table style="width:50%" style = "background-color: transparent;">
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>GRADE</th> 

  </tr>


<?php

     $sql = "SELECT id, name, grade FROM students";
    $result = $conn -> query ($sql);

    if($result -> num_rows >0){
        //output data of each row

        while($row = $result -> fetch_assoc()){
            ?>
            <tr>
            <td> <?php echo $row["id"] ?> </td>
            <td> <?php echo $row["name"] ?> </td>
            <td> <?php echo $row["grade"] ?> </td>

            </tr>

?>



</table>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 1
    Yes, it's possible to collect input from a user and save it to a database. Have you tried anything? It sounds like you should be starting with some introductory PHP/MySQL tutorials. – David Mar 23 '17 at 18:24
  • 1
    There's a lot to this question; `
    ` and its `` fields (one input for each `$row`'s `grade` value, a method to `POST` this (whether AJAX or a straight submitted request), PHP logic to handle the submitted info and save that to the database, etc etc.
    – Tim Lewis Mar 23 '17 at 18:29

1 Answers1

0

Research a bit on HTML forms here HTML Forms

You can either use post or get methods for the form to send the values to PHP.

After you have set up your form you can simply use the variables $_GET[formvariable] if you are using get or $_POST[formvariable] if you are using post.

You can then use mysql to update values in the database when the form is submitted.

George Jones
  • 245
  • 2
  • 11