How To Fill Input Fields In Form With Data From Row In Html Table I Want To Edit
I have this HTML table with data from MySQL database and form for adding/editing rows in this table. If I add new row, everything works fine, but when I want to edit, I dont know h
Solution 1:
I was on the same page when I have started.
You should use
echo "<a href=\"edit.php?id=".$row['id']."\"><i class='glyphicon glyphicon-pencil' id=$id></i></a>
On edit.php you will use $_GET['id'] to get the id of clicked element.
Solution 2:
You need to tell you script whichrecord you want to edit.
Best way will be to add href to your edit anchor.
echo "<a href="/url/to/this/script?id=$id"><i class='glyphicon glyphicon-pencil' id=$id></i></a></td>
Now after refresh you can get id of record you want to edit by:
// this way provide some base security
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
// Now get record from database (only sample call - need to build prepare statement)
$record = $database->getRecordById($id);
// After that fill form with record data
<input type="text" name="name" placeholder="Jmeno" value="<?php $record->name ?>" required autofocus>
Solution 3:
I found a solution I was looking for. Advices from guys here are right as well in case it never mind you redirect from your site.
I wanted to do it dynamically with jQuery if it would be possible and I've found this solution which works for me perfect, so I share it here.
Post a Comment for "How To Fill Input Fields In Form With Data From Row In Html Table I Want To Edit"