iblackedout Posted November 21, 2008 Share Posted November 21, 2008 Hey, I created a very simple script that works fine that I am using as part of an Admin Panel for managing user accounts. It outputs data from the database into a simple table where I then use a form to run SQL queries to modify the data. The way I have it set up now is a little inconvenient: I have to manually input the member's username into a textfield so the variable can be set for the SQL query. I don't want to have to copy-paste the username into the textfield everytime I want to make a modification. Now, what I would like to do is output the data into a table but with the username as a radio button so, for example, when I press the "Delete Member" button, it uses the value of the checked radio button as the "selected username" variable used in the SQL query. Here is what I have now: <?php // Check if person viewing is admin require_once('auth-admin.php'); // Connect to Database require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } // Collect the data contained in MySQL table $query="SELECT * FROM members"; $result=mysql_query($query); // Count how many variables were collected so that it may be divided $countrows=mysql_numrows($result); mysql_close(); echo "<table border='0'> <tr> <th>User ID</th> <th>Name</th> <th>Username</th> <th>Email</th> <th>Privelege Level</th> </tr>\n"; //Display output $i=0; while ($i < $countrows) { $dispid=mysql_result($result,$i,"member_id"); $dispname=mysql_result($result,$i,"name"); $dispuser=mysql_result($result,$i,"username"); $dispmail=mysql_result($result,$i,"email"); $disppass=mysql_result($result,$i,"password"); $displevel=mysql_result($result,$i,"level"); echo " <tr> <td>$dispid</td> <td>$dispname</td> <td>$dispuser</td> <td>$dispmail</td> <td>$displevel</td> </tr>"; $i++; } echo "</table>" ?> <br /> <form id="modifylvl" name="modifylvl" method="post" action="domod.php"> <table border="0" align="left"> <tr> <td><b>Username</b></td> <td><b>New Level</b></td> </tr> <tr> <td><input name="username" type="text" class="textfield" id="username" /></td> <td> <select name="newlevel" id="newlevel"> <option value="1">1 <option value="2">2 <option value="9">9 </select> </td> <td><input type="submit" name="Submit" value="Modify" /></td> </tr> </table> </form> <p> <table border="0" align="left"> <tr> <td><b>Member</b></td> <td>1</td> </tr> <tr> <td><b>Artist</b></td> <td>2</td> </tr> <tr> <td><b>Admin</b></td> <td>9</td> </tr> </table> 1. How do I add the radio buttons with the name and value set to the outputted usernames? 2. Is it possible to use the same form for different operations such as "Delete User", "Modify Privelege Level", etc. ? Link to comment https://forums.phpfreaks.com/topic/133608-adding-radio-buttons-to-mysql-output/ Share on other sites More sharing options...
iblackedout Posted November 21, 2008 Author Share Posted November 21, 2008 I gave it a shot and found the answer to my first question. I simply had to create a new column in the table in my while loop with the following code: <td><input type='radio' name='selecteduser' value='"; ?> <?php echo "$dispuser" ?> <?php echo "' /></td> I then used $_POST['selecteduser'] as a variable in my query. Link to comment https://forums.phpfreaks.com/topic/133608-adding-radio-buttons-to-mysql-output/#findComment-695132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.