I'm trying to post a new record in a table with <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
. But every row in my table has an unique id, and that id is put next to every name
. So I'm trying to get the id with $_GET
but it's been unsuccesful so far. Is the method I'm trying wrong or am I doing something else wrong? If anybody can tell me what's going wrong, I'd appreciatie.
PHP that gets placed above <html>
<?php
if (isset($_POST['saveRecord'])) {
if (isset($_POST["newRecord"]) && !empty($_POST["newRecord"])) {
$id = $_GET['record'];
$klant=$_POST['newRecord'].$id;
$query = "INSERT INTO table2
(recordid, recordname)
VALUES
(NULL, '$record')";
mysqli_query($con, $query);
}
}
?>
Markup
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<?php
$query = ("select * from table1");
$result = mysqli_query($con, $query) or die (mysqli_error());
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$id = $row['rowid'];
?>
<tr>
<td>
<input class="newRecord<?php echo $id; ?>" type="text" name="newRecord<?php echo $id; ?>" />
<a href="?record=<?php echo $id; ?>">
<button class="saveRecord<?php echo $id; ?>" name="saveRecord<?php echo $id; ?>">Save</button>
</a>
</td>
</tr>
<?php } ?>
</table>
</form>