searls03 Posted April 8, 2011 Share Posted April 8, 2011 ok, so I have this code: <?php if (isset($_POST['submitted'])) { include('connect1.php'); $category = $_POST['category']; $criteria = $_POST['criteria'] ; $query = ("SELECT name, badges, rank, userid FROM members WHERE $category LIKE '%".$criteria."%'"); $result = mysqli_query($dbcon, $query) or die('error getting data'); $num_rows = mysqli_num_rows($result); echo "$num_rows results found"; echo "<table width=\"896\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr bgcolor=\"#F7E496\"><td bgcolor=\"#F7E496\"><strong>name</strong></td><td bgcolor=\"#F7E496\" ><strong>Merit Badges</strong></td><td bgcolor=\"#F7E496\"><strong>Rank</strong></td><td bgclor=\"#F7E496\"></td></tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {$color = ($color == 'white')?'#fffccc':'white'; echo "<tr bgcolor='$color'><td> <input type=\"text\" name=\"userid\" id=\"userid\" value='".$row['userid']."'>"; echo $row['name']; echo " </td><td> <form action=\"scout.php\" method=\"post\"> <textarea name=\"badges\" id=\"badges\" cols=\"40\" rows=\"3\" type=\"textarea\">".$row['badges']."</textarea></td><td> <span class=\"adfa\"> </span> <select name=\"rank\" id=\"rank\"> <option value=\"Scout\">Scout</option> <option value=\"Tenderfoot\">Tenderfoot</option> <option value=\"Second Class Scout\">Second Class Scout</option> <option value=\"First Class Scout\">First Class Scout</option> <option value=\"Star Scout\">Star Scout</option> <option value=\"Life Scout\">Life Scout</option> <option value=\"Eagle Scout\">Eagle Scout</option> <option value=\"\" selected=\"selected\">".$row['rank']."</option> </td><td>"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Save\" /> "; echo "</form>"; } echo "</table>"; echo "</td></tr>"; } ?> and this is the code that does the posting: <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ [url=http://'http://www.flashbuilding.com/']www.flashbuilding.com[/url] -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display // Process the form if it is submitted if ($_POST['submit']) { $badges = $_POST['badges']; $userid = $_POST['userid']; $rank = $_POST['rank']; $sql = mysql_query("UPDATE members SET badges='$badges', rank='$rank' WHERE userid='".$_GET['userid']."'"); printf("Records updated: %d\n", mysql_affected_rows()) ; exit(); } // close if post ?> So what I need to know is how I can make it so that each result has it's user id associated with it......and I can update multiple rows at once according to each userid that is associated..........right now I can only get it to do one if I add on ?userid=".$row['userid']." in the first piece of code.......how can I make it update lets say 78 as soon as I click submit...... PS I know there will be a submit button with each row right now.......I will move it out of the loop later..... Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/ Share on other sites More sharing options...
dawsba Posted April 8, 2011 Share Posted April 8, 2011 set it to a html array and on post spin through the keys <?php if (isset($_POST['submitted'])) { include('connect1.php'); $category = $_POST['category']; $criteria = $_POST['criteria'] ; $query = ("SELECT name, badges, rank, userid FROM members WHERE $category LIKE '%".$criteria."%'"); $result = mysqli_query($dbcon, $query) or die('error getting data'); $num_rows = mysqli_num_rows($result); echo "$num_rows results found"; echo "<table width=\"896\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr bgcolor=\"#F7E496\"><td bgcolor=\"#F7E496\"><strong>name</strong></td><td bgcolor=\"#F7E496\" ><strong>Merit Badges</strong></td><td bgcolor=\"#F7E496\"><strong>Rank</strong></td><td bgclor=\"#F7E496\"></td></tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {$color = ($color == 'white')?'#fffccc':'white'; echo "<tr bgcolor='$color'><td> <input type=\"text\" name=\"userid\" id=\"userid\" value='".$row['userid']."'>"; echo $row['name']; echo " </td><td> <form action=\"scout.php\" method=\"post\"> <textarea name=\"badges[color=red][".$row['userid']."][/color]\" id=\"badges\" cols=\"40\" rows=\"3\" type=\"textarea\">".$row['badges']."</textarea></td><td> <span class=\"adfa\"> </span> <select name=\"rank[color=red][".$row['userid']."][/color]\" id=\"rank\"> <option value=\"Scout\">Scout</option> <option value=\"Tenderfoot\">Tenderfoot</option> <option value=\"Second Class Scout\">Second Class Scout</option> <option value=\"First Class Scout\">First Class Scout</option> <option value=\"Star Scout\">Star Scout</option> <option value=\"Life Scout\">Life Scout</option> <option value=\"Eagle Scout\">Eagle Scout</option> <option value=\"\" selected=\"selected\">".$row['rank']."</option> </td><td>"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Save\" /> "; echo "</form>"; } echo "</table>"; echo "</td></tr>"; } ?> and on the post side <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ [url=http://'http://www.flashbuilding.com/']www.flashbuilding.com[/url] -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display // Process the form if it is submitted if ($_POST['submit']) { $PS = $_POST['submit']; if(is_array($PS)) { foreach($PS as $user_id=>$type) { $badges=$type[badges]; $rand = $type[rank]; //user_id is now defined spin sql $sql = mysql_query("UPDATE members SET badges='$badges', rank='$rank' WHERE userid='".$user_id."'"); printf("Records updated: %d\n", mysql_affected_rows()) } } exit(); } // close if post ?> not tested but should give u a start Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1198565 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 it is not posting to database. Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199082 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 oh yeah....the code was broken.....here is what I fixed it with: <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ [url=http://'http://www.flashbuilding.com/']www.flashbuilding.com[/url] -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display // Process the form if it is submitted if ($_POST['submit']) { $PS = $_POST['submit']; if(is_array($PS)) { foreach($PS as $user_id=>$type) { $badges = $type['badges']; $rank = $type['rank']; //user_id is now defined spin sql $sql = mysql_query("UPDATE members SET badges='$badges', rank='$rank' WHERE userid='".$user_id."'"); printf("Records updated: %d\n", mysql_affected_rows()); } } exit(); } // close if post ?> Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199085 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 what should I fix with it now? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199343 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 what is $PS? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199351 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 is the array set up correctly? what about anything else? why wont this work.......the records updated doesn't show up so clearly something isn't working in the loop...... Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199370 Share on other sites More sharing options...
searls03 Posted April 9, 2011 Author Share Posted April 9, 2011 k, so I figured out I needed to make submit an array...............although I don't think that is what I want to do is it? <?php if (isset($_POST['submitted'])) { include('connect1.php'); $category = $_POST['category']; $criteria = $_POST['criteria'] ; $query = ("SELECT name, badges, rank, userid FROM members WHERE $category LIKE '%".$criteria."%'"); $result = mysqli_query($dbcon, $query) or die('error getting data'); $num_rows = mysqli_num_rows($result); echo "$num_rows results found"; echo "<table width=\"896\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr bgcolor=\"#F7E496\"><td bgcolor=\"#F7E496\"><strong>name</strong></td><td bgcolor=\"#F7E496\" ><strong>Merit Badges</strong></td><td bgcolor=\"#F7E496\"><strong>Rank</strong></td><td bgclor=\"#F7E496\"></td></tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {$color = ($color == 'white')?'#fffccc':'white'; echo "<tr bgcolor='$color'><td> "; echo $row['name']; echo " </td><td> <form action=\"scout.php\" method=\"post\"> <input type=\"text\" name=\"userid\" id=\"userid\" value='".$row['userid']."'> <textarea name=\"badges[".$row['userid']."]\" id=\"badges\" cols=\"40\" rows=\"3\" type=\"textarea\">".$row['badges']."</textarea></td><td> <span class=\"adfa\"> </span> <select name=\"rank[".$row['userid']."]\" id=\"rank\"> <option value=\"Scout\">Scout</option> <option value=\"Tenderfoot\">Tenderfoot</option> <option value=\"Second Class Scout\">Second Class Scout</option> <option value=\"First Class Scout\">First Class Scout</option> <option value=\"Star Scout\">Star Scout</option> <option value=\"Life Scout\">Life Scout</option> <option value=\"Eagle Scout\">Eagle Scout</option> <option value=\"\" selected=\"selected\">".$row['rank']."</option> </td><td>"; } echo "</td></tr>"; echo "</table>"; echo "<input type=\"submit\" name='submit[".$row['userid']."]' id=\"submit\" value=\"Save\" /> </form>"; } ?> Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199385 Share on other sites More sharing options...
searls03 Posted April 10, 2011 Author Share Posted April 10, 2011 So which piece should be in the array part of the loop of the if statement..........does this make sense? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199498 Share on other sites More sharing options...
searls03 Posted April 10, 2011 Author Share Posted April 10, 2011 any suggestions???????? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1199663 Share on other sites More sharing options...
searls03 Posted April 13, 2011 Author Share Posted April 13, 2011 help? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1200911 Share on other sites More sharing options...
searls03 Posted April 15, 2011 Author Share Posted April 15, 2011 anything? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1202201 Share on other sites More sharing options...
searls03 Posted April 16, 2011 Author Share Posted April 16, 2011 any? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1202373 Share on other sites More sharing options...
searls03 Posted April 21, 2011 Author Share Posted April 21, 2011 any help anybody? I need this working!!!!!!!!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1204474 Share on other sites More sharing options...
searls03 Posted April 22, 2011 Author Share Posted April 22, 2011 anything? Link to comment https://forums.phpfreaks.com/topic/233039-update-multiple-user-profiles/#findComment-1204841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.