PHP rows send 1 mySQLi record to form for edit

36 views Asked by At

How would you (PHP only) set up data so you could pass the record ID of a chosen row to a form for processing?

I have a table from a SELECT * all records. At end of each row there is an Edit button and a hidden key named sid. No matter which row chosen, the last sid created gets passed and so (of course) the last record gets SELECT'd. Here's the failing code for the submit and hidden key.

      echo "\t<td><input type='submit' value='Edit' name='submit'>"; 
      echo "\t<input type='hidden' value=$sid name='sid'></td>\n";

My hack worked to change the name of the edit button to the value of the recordID but that's cheating. Then I can just do $key = $_POST[submit] on the next page:

      echo "\t<td><input type='submit' value='$sid' name='submit'>"; //yes thats a hack
      echo "\t<input type='hidden' value=$sid name='sid'></td>\n";

So here's my question again: Can you and... how would you, pass the ID (first field in row) to the form? In (perhaps) a hidden input? (PHP only not yet PDO or prep'd. I'm trying to learn this with just PHP before moving on to Ajax etc.)

BTW, here's how I populate the columns of each row before the submit at end of row:

      foreach ($row as $key=>$value) {
        echo "<td>" .$value ."</td>\n"; 
        }

One solution that I thought of was autoincrementing the name of the sid of each row, but then how would I know its name to get at its value?

I know eventually that I'll just transform the chosen row into an edit from with some AJAX magic.

0

There are 0 answers