Link to home
Start Free TrialLog in
Avatar of Oldiesmann
Oldiesmann

asked on

HTTP_POST_VARS not being set?

I have been trying to figure this out for several days now... I have this thing created that allows users to select "moods" by clicking on an image, and I want the board administrators to be able to re-order/rename the moods, but it won't work. Here's the basic info:

Each mood has 4 values associated with it: an Auto-incrementing ID, a name, a filename and an order ID, which defaults to 0.

Below is the section of the code that loads the table info to show the values for the mood and allow the person to change them ($db_prefix is a global variable set in another file, $cgi is "/index.php?board=", $imagesdir is a reference to the location of the image files for the board, and all the text variables are also set in another file). The form loads everything just fine, but when I click on submit, it doesn't update the changes, and I did some testing and found that it wasn't setting the $HTTP_POST_VARS values in the second function:

      $get_moods = mysql_query("SELECT * FROM {$db_prefix}moods WHERE id='$id' ORDER BY oid ASC");
      echo '
      <form action="' . $cgi . ';action=modifymoods" method="POST">
      <table border="1" width="100%" cellspacing="0" cellpadding="0" bgcolor="' . $color['bordercolor'] . '" class="bordercolor" align="center">
      <tr>
            <td valign="middle" align="left" class="titlebg" bgcolor="' . $color['titlebg'] . '" colspan="5" height=22><img src="' . $imagesdir . '/grin.gif" /></td>
            <td valign="middle" align="center" class="titlebg" bgcolor="' . $color['titlebg'] . '" colspan="5" height=22><b><font size="2" class="text1" color="' . $color['titletext'] . '">' . $moodtxt[8] . '</font></b></td>
      </tr></table>
      <table border="0" width="100%" cellspacing="1" cellpadding="1" bgcolor="' . $color['bordercolor'] . '" class="bordercolor" align="center">
      <tr>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" width="30%" align="center">' . $moodtxt['6']. '</td>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" width="30%" align="center">' . $moodtxt['7'] . '</td>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" width="30%" align="center">' . $moodtxt['13'] . '</td>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" width="30%" align="center">Mood Image</td>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" width="10%" align="center"></td>
      </tr>';

      $i = 1;
      while ($mood = mysql_fetch_assoc($get_moods)) {
            echo '
            <tr>
                  <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="30%" align="center"><input type="text" name="name$i" value="' . $mood[name] . '"></td>
                  <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="30%" align="center"><input type="text" name="fn$i" value="' . $mood[filename] . '"></td>
                  <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="30%" align="center"><input type="text" name="oid$i" value="' . $mood[oid] . '"></td>
                  <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="30%" align="center"><img src="' . $imagesdir . '/' . $mood[filename] . '" alt="' . $mood[name] . '">';
                  
                  if ($MenuType == 1) { echo' <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="10%" align="center"><a href="index.php?action=deletemood&id=' . $mood[id] . '">' . $moodtxt['14'] . '</a></td>';}
                  else { echo' <td class="windowbg" bgcolor="' . $color['windowbg'] . '" width="10%" align="center"><a href="index.php?action=deletemood&id=' . $mood[id] . '"><img src="' . $imagesdir . '/delete.gif" border=0 /></a></td>'; }
            echo'</tr>';
            $i++;
            }
      echo '
      <tr>
            <td class="catbg" bgcolor="' . $color['catbg'] . '" align="center" colspan="5"><input type="submit" value="Modify Moods"><br /></td>
      </tr>
      </table>
      </form>';
      footer();
    obExit();
}</pre>

function ModifyMoods2() {
      global $db_prefix, $HTTP_POST_VARS, $fn, $name, $oid, $id, $sourcedir;      

      $i = 1;
      $get_moods = mysql_query("SELECT * FROM {$db_prefix}moods WHERE id='$id' ORDER BY oid ASC");

      while ($mood = mysql_fetch_assoc($get_moods)) {
            if (isset($HTTP_POST_VARS["name$i"])) {
                  if (isset($HTTP_POST_VARS["fn$i"])) {
                        if (isset($HTTP_POST_VARS["oid$i"])) {
                              $name = $HTTP_POST_VARS["name$i"];
                              $fn = $HTTP_POST_VARS["fn$i"];
                              $oid = $HTTP_POST_VARS["oid$i"];
                              
                              $result = mysql_query("
                                                UPDATE {$db_prefix}moods
                                                SET name='$name', filename='$fn', oid='$oid'
                                                WHERE (id='$id')");
                              
                              if (!$result) { echo(mysql_error()); }
                              }
                        }
                  }
            $i++;
            }
      include_once("$sourcedir/Admin.php");
      Admin();
      }

Any ideas as to why this isn't working?
ASKER CERTIFIED SOLUTION
Avatar of joaocmreis
joaocmreis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Oldiesmann
Oldiesmann

ASKER

Sorry to confuse you... This is all part of a large messageboard system. I should have mentioned that the form actions are defined in the main index.php file... Basically, it creates an array pointing it to the various files and functions, so it's kind of like this: 'modifymoods' => array("$sourcedir/Moods.php", 'ModifyMoods2').
Here's a better explanation of how the "action=" part of the script works...
The actions are all defined in a large array in index.php
Each "action" is defined as followed:

'action'=>("file.php",'function')

So, basically this says that whenever the script sees the specified action in the url, to go to the specified function in the specified file, in this case, whenever the script sees "action=modifymoods", it will go to the ModifyMoods2 function in moods.php.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation in the Cleanup topic area:

Answered by joaocmreis

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

snoyes_jw
EE Cleanup Volunteer
I haven't commented in a while because I was hoping someone would be able to answer my question as to why it won't update the database. I'm not having problems getting it to go to the function. I'm having problems getting it to update the values. My comment after joacmreis' comment was to clarify how the functions are being called. It's getting to the function just fine, but doesn't update the values in the database like it should.
I see you used things like $HTTP_POST_VARS["name$i"].  I don't think it will expand that to name1, name2, etc.  Try $HTTP_POST_VARS["name" . $i] instead.
Having tried it, I guess I was wrong.  It will expand that out.  Let me keep looking.
Does $db_prefix have a trailing . so that you get dbname.moods rather than dbnamemoods?

Have you tried adding a print_r($mood) inside the while loop to see if there were any records returned?
Try also a print_r($HTTP_POST_VARS) to make sure that you have entries for $HTTP_POST_VARS['name1'], etc.
I'll try the print_r things... It's getting the values from the database just fine as well, so the $db_prefix thing isn't the problem.