PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am kind of new to PHP, and I am having issues with this set up. Basically I have a html table that is filled with data from mysql and using PHP. Now the table has a column with a button 'update'. And what I want to do is when the Update button is clicked, i want to post the values of that row to the same page again to update it after a if(isset ($_POST['update'])){}. I am just not sure how to do this... I do not know ajax or json which was one of the alternatives.. Is there an easier way to do this?
I also tried adding a form to each row but did not work
edprog wrote:I also tried adding a form to each row but did not work
You'll have to do this; it's easier than submitting the whole page and picking out select $_POST values. The thing to remember here is to make each form post a unique value; you can do this by using a hidden field
<?php
// print("<p style='font-size:14px; color:blue; padding:0;'>$client_id</p>");
print('<input type="hidden" name="userID" value="' . $client_id . '" />');
// since all the forms contain the same fields, the rest is uncomplicated
// ----
if (isset($_POST['submitBtn'])) {
$id = $_POST['userID'];
// get rest of your data
$sql = "UPDATE table SET field = $value WHERE id = $id";
?>
This is a simple example without any security features which you should include (security features that is) in your final script
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Great, one last question.. This file is a file that is included on another page, and that other page already has a <form> and this code goes below it so how can i have so many <forms> in a page>
As long as you close the form tags properly and don't have a form inside a form there shouldn't be a problem. Each submit button works within it's specified form.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering