CBaZ Posted July 22, 2007 Share Posted July 22, 2007 <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? Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/ Share on other sites More sharing options...
wildteen88 Posted July 22, 2007 Share Posted July 22, 2007 The variable $x[user_id] is being created in the while loop. You can only use variables after they have been defined you cannot use them before they are defined. PHP does not backtrack. What are you trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-304695 Share on other sites More sharing options...
CBaZ Posted July 22, 2007 Author Share Posted July 22, 2007 i need the id number in that line profile2.php?user_id=<?php echo $x[user_id] so that when i click view it goes to the selected username's profile. maybe this can be done a different way Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-304699 Share on other sites More sharing options...
wildteen88 Posted July 22, 2007 Share Posted July 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-304926 Share on other sites More sharing options...
CBaZ Posted July 23, 2007 Author Share Posted July 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-305034 Share on other sites More sharing options...
wildteen88 Posted July 23, 2007 Share Posted July 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-305503 Share on other sites More sharing options...
CBaZ Posted July 23, 2007 Author Share Posted July 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/61241-form-action-trouble/#findComment-305610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.