Question

I've been around this for hours now and I don't know where to turn.

I want to update a field in output PHP query from mysql in a table.

All I need is a little button or something like that to insert "Yes" to a field in that record.

Here's my code:

<body>
<?php
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is the password
mysql_select_db('test');

mysql_set_charset('utf8');

$query = "SELECT * FROM simulac";
$result = mysql_query($query);

echo "<table>"; // start a table tag in the HTML

while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['name'] . "</td><td>" . $row['over'] . "</td><td><form action="" method="POST"><input type="submit" value="Concluido" name="submit" class="enviar" /></form></td></tr>";  }

echo "</table>"; //Close the table in HTML

mysql_close(); //Make sure to close out the database connection

?>

</body>

I just stopped here because it started to get me errors and I wonder if there is a better way of doing this..

Was it helpful?

Solution

Try someting in this order (seems better to me)

<form>
<table>
<tr>

<td>...
</td>
<td>...
</td>
<td>
   <?php echo('<input type="submit" value="Concluido" name="submit.'['.$row['id'].']'. '" class="enviar" />'?>
</td>


</tr>
</table>

</form>

//Check button
<?php
if (isset($_POST['submit'])) {
    reset($_POST['submit']);
    foreach ($_POST['submit'] as $name => $value) {
        //do some update on ... $name);
    }
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top