Jump to content

form action trouble


CBaZ

Recommended Posts

<form name="profileview" method="post" action="profile2.php?user_id=<?php echo $x[user_id]?>">

<?php

echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";

echo "<tr>\n";

echo "<td>View:</td>\n";

echo "<td><select name=\"\">\n";

echo "<option value=\"\"></option>\n";

 

 

$sql = mysql_query("SELECT * FROM users WHERE user_id != '$user_id' ORDER BY username");

if (mysql_num_rows($sql) > 0) {

  while ($x = mysql_fetch_assoc($sql)) echo "<option value=\"\">$x[username], $x[user_id]</option>\n";

}

 

echo "</td>\n";

echo "</tr>\n";

echo "<tr>\n";

echo "<td></td>\n";

echo "<input name=\"action\" type=\"hidden\" id=\"action\" value=\"View\">\n";

echo "<td><input type=\"submit\" name=\"submit\" value=\"View\" /></td>\n";

echo "</tr>\n";

echo "</table>\n";

echo "</form></left>\n";

 

?>

 

<form name="profileview" method="post" action="profile2.php?user_id=<?php echo $x[user_id]?>">

in question here is this $x[user_id] i get no id in the action line but i do get username and id for the option value in script above.

how is it that i can get this same id into the action line? anyone have any ideas?

Link to comment
Share on other sites

Cant you just add a hidden form field which holds the value of $x[user_id]?

 

Also I cannot understand your code. When you submit the form only the submit button and the hidden form field values will be returned but not the value from the drop down menu.

Link to comment
Share on other sites

ok the pull down menu has values .. it displays the username and the id

 

the only place i do not get an id value is in the first line with the form ...

 

you know where i have action="profile2.php?user_id=<?php echo $x[user_id]?>">

 

this one is not gettin the id value and if it gets it its always constant ...

 

so one id works but not the selected one from the pulldown.

Link to comment
Share on other sites

If you want the pull dowm menu to return the user id you will have to name the drop downbox using the name html attribute inside the select tag, eg:

<select name="user_id">

. Then you want to store each seperate users users id in the value attribute for the option tag. eg:

<option value="[user_id_here]">[user_name_here]</option>

 

So putting it all together you get this:

<form name="profileview" method="post" action="profile2.php">
<?php
echo <<<EOF
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>View:</td>
    <td>
      <select name="user_id">
        <option>Select User:</option>

EOF;

$sql = mysql_query("SELECT * FROM users WHERE user_id != '$user_id' ORDER BY username");
if (mysql_num_rows($sql) > 0)
{
    while ($row = mysql_fetch_assoc($sql))
    {
        echo '<option value="' . $row['user_id'] . '">' . $x['username'] . "</option>\n          ";
    }
}

echo <<<EOF
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <input name="action" type="hidden" id="action" value="View">
      <input type="submit" name="submit" value="View" />
    </td>
  </tr>
</table>
</form>
EOF;

?>

In profile2.php you use $_POST['user_id'] to retrieve the users id that was selected in the drop down list.

Link to comment
Share on other sites

thanks .. i much appreciated this one.  I possibly have another code in question my usersonline code i will post it for your viewing.

$result2 = mysql_query("SELECT COUNT(*) AS count FROM users WHERE permission = '0'");

$row = mysql_fetch_array($result2);

 

$result3 = mysql_query("SELECT COUNT(*) AS count FROM users WHERE permission = '1'");

$row2 = mysql_fetch_array($result3);

 

echo "ATM:" . ($usersOnline != 1 ? "" : "") . " $usersOnline Admin" . ($usersOnline != 1 ? "s" : "") ." / $row2[count]" . ", " . ($usersOnline != 1 ? "" : "") . " $usersOnline User" . ($usersOnline != 1 ? "s" : "") ." / $row[count]" . ". ";

 

now the permission 0 comes out fine but the admins are not fine at all.  i have 2 admins everytime i login as a user it adds admins as well and goes beyond the possible 2.  i may have to give you more code then this let me know.

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.