Jump to content

update multiple user profiles


searls03

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.