Ryflex Posted December 11, 2010 Share Posted December 11, 2010 Hi all, I'm currently working on an admin page and I'm trying to figure out how I can make an update query where all information will be updated. The code below is where I extract all the Users and their status from the database and now I when the statuses are updated in the text fields they need to be send to the database. Does anyone know how this could be done? Thnx Ryflex <?php require_once('auth.php'); require_once('config.php'); $global_dbh = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect to database"); mysql_select_db(DB_DATABASE, $global_dbh) or die("Could not select database"); $user_query = "SELECT * FROM members"; $user_result = mysql_query($user_query); ?> <form ID="gotoresource" NAME="gotoresource" METHOD="POST" ACTION="admin_exec.php"> <table width="500" border="1" align="center" cellpadding="2" cellspacing="0"> <tr> <td><b>ID</b></td> <td><b>User</b></td> <td><b>Status</b></td> </tr> <?php while($row = mysql_fetch_assoc($user_result)) { echo "<tr>"; echo "<td>"; echo $row['member_id']; echo "</td>"; echo "<td>"; echo $row['login']; echo "</td>"; ?> <td> <input type="text" name="status" value="<?php echo $row['status'];?>" /> </td> <?php echo "</tr>"; } ?> <input type="image" src="/images/button.gif" alt="Submit button"> </form> <html> <head> <title>AdminPage</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/221332-updating-multiple-rows-in-one-page/ Share on other sites More sharing options...
OOP Posted December 11, 2010 Share Posted December 11, 2010 Hi there, you need to update the below code: <input type="text" name="status" value="<?php echo $row['status'];?>" /> to this in order to have an array of all status extracted from the database <input type="text" name="status[]" value="<?php echo $row['status'];?>" /> Then in your script that will handle the update, you can do something like this foreach ($_POST['status'] AS $status){ // Apply your MYSQL update statement here } Quote Link to comment https://forums.phpfreaks.com/topic/221332-updating-multiple-rows-in-one-page/#findComment-1145855 Share on other sites More sharing options...
Ryflex Posted December 12, 2010 Author Share Posted December 12, 2010 Hi, Thnx OOP for the reaction. I changed the $status to $status[] and made following as the exec page. Somehow it takes the last status number in the table and sets every row in the table with that number.... Anyone knows how to solve that??? Thnx Ryflex <?php require_once('auth.php'); require_once('config.php'); $global_dbh = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect to database"); mysql_select_db(DB_DATABASE, $global_dbh) or die("Could not select database"); foreach ($_POST['status'] AS $status) { $stat = $_POST['status']; $update = "UPDATE members SET status = '$stat'"; $update_result = mysql_query($update); echo "$status<BR>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221332-updating-multiple-rows-in-one-page/#findComment-1146093 Share on other sites More sharing options...
harristweed Posted December 12, 2010 Share Posted December 12, 2010 You might get a clue from this: http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database Quote Link to comment https://forums.phpfreaks.com/topic/221332-updating-multiple-rows-in-one-page/#findComment-1146094 Share on other sites More sharing options...
Ryflex Posted December 12, 2010 Author Share Posted December 12, 2010 Thnx Great tutorial works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/221332-updating-multiple-rows-in-one-page/#findComment-1146127 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.