0

I'm trying to create a form which allows a user to edit multiple members' information, taking that information in, and passing it through the URL to edit the database. I have this so far:

 echo "<form id='memberEditor' method='post' action='massEditor.php'>"
 $result = mysql_query("SELECT * FROM `user_trials` ORDER BY `grade` ASC, `lastName` ASC");

            while($row = mysql_fetch_array($result)){
                $studentID = $row['studentid'];
                $ID = array();
                array_push($ID, $studentID);                                        
                $firstName = $row['name'];
                $lastName = $row['lastName'];
                $fullName = $firstName." ".$lastName;
                $money = $row['money'];
                $moneyValue = array();
                array_push($moneyValue, $money);
                $waiver = $row['waiver'];
                $waiverValue = array();
                array_push($waiverValue, $waiver);
                echo "<tr>";
                echo "<td>$studentID</td>";
                echo "<td>$fullName </td>";                 
                echo "<td><input type='checkbox' name='money' id='money'".(($money == 'yes')?'checked ':' ')."value='yes' /></td>";
                echo "<td><input type='checkbox' name='waiver' id='waiver'".(($waiver == 'yes')?'"checked"':' ')."value='yes' /></td>";
                echo "</tr>";

            }
            $queryID = http_build_query($studentID);
            $queryMoney = http_build_query($moneyValue);
            $queryWaiver = http_build_query($waiverValue);

and at the top of the page, where I'm trying to get the arrays in order to edit the database:

 ini_set('display_errors', 'On');
error_reporting(E_ALL);

  $memberNumbers = count($ID);
  for($i = 0; $i < $memberNumbers; $i++) {
      $studentid = $ID[$i];         
      $result = mysql_query("SELECT * FROM `user` WHERE `studentid`='$studentid' LIMIT 1");
      $news = mysql_fetch_array($result);   
      $cash = $moneyValue[$i];
      $permission = $waiverValue[$i];
      mysql_query("UPDATE `user_trials` SET `money`='$cash', `waiver`='$permission' WHERE `studentid`='$studentid' LIMIT 1");
      header("Location: view_members.php"); 
}

I've tried to pass the the data from http_build_query into the URL and then retrieving it at the top, but I have no idea as to how I am supposed to add multiple arrays into the URL and then separate the three in order to have three distinct arrays to get information from. Thanks!

Andrew
  • 3,501
  • 8
  • 35
  • 54
  • 2
    mysql_* functions shouldn't be used! See http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php –  Mar 08 '13 at 02:42
  • 1
    little confusing, you r using post not get for a start, so it's not in the url. `print_r($_POST)` on massEditor.php will show you what you have to work with –  Mar 08 '13 at 02:45
  • 1
    @MichaelN his question was nothing to do with the mysql –  Mar 08 '13 at 02:45
  • @Dagon Doesn't mean that bad practices shouldn't be picked up and commented on. –  Mar 08 '13 at 02:50
  • 1
    it does when its done 100 times a day. –  Mar 08 '13 at 02:54
  • How do I do that? Is there a better way to do what I'm trying to do? – Andrew Mar 08 '13 at 03:03
  • I don't even know where to begin with this one, this is just so wrong. – Jonast92 Mar 08 '13 at 03:09
  • Check here how you can NOT use mysql specific syntax: http://stackoverflow.com/questions/15256247/i-cant-get-the-form-data-to-go-into-database-what-am-i-doing-wrong/15256553#15256553 – Jonast92 Mar 08 '13 at 03:10

1 Answers1

0

You can use serialization and urlencoding to send multiple arrays through hidden tag element of form tag and urldecoding and unserialization to display the data. For eg.:

For Sending The data you can try :

<?php
    $array1["a"] = "Element 1 Of Array 1";
    $array1["b"] = "Element 2 Of Array 1";
    $array1["c"] = "Element 3 Of Array 1";
    $array1["d"] = "Element 4 Of Array 1";
    $str1 = serialize($array1);  //****** To Serialize The Array ****
    $strenc1 = urlencode($str1); //****** For URL Encoding **********

    $array2[1] = "Element 1 Of Array 2";
    $array2[2] = "Element 2 Of Array 2";
    $array2[3] = "Element 3 Of Array 2";
    $array2[4] = "Element 4 Of Array 2";
    $str2 = serialize($array2);  //****** To Serialize The Array ****
    $strenc2 = urlencode($str2); //****** For URL Encoding **********
?>

<form method="post" action="target.php">
    <!-- Passing Array 1 -->
    <input type="hidden" name="arr1" value="<?php echo $strenc1; ?>" /> 
    <!-- Passing Array 2 -->
    <input type="hidden" name="arr2" value="<?php echo $strenc2; ?>" />
    <input type="submit" />
</form>

And then you can print the data on target page using:

<?php
    $a = unserialize(urldecode($_POST['arr1']));
    foreach($a as $x)
        echo $x . "<br />";

    $a = unserialize(urldecode($_POST['arr2']));
    foreach($a as $x)
        echo $x . "<br />";
?>

Hope this will solve you problem. :)

Nitesh Gupta
  • 215
  • 1
  • 11