Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Updating several records with Radio Buttons
Old 04-29-2005, 05:29 PM Updating several records with Radio Buttons
Monkeon's Avatar
Skilled Talker

Posts: 59
Trades: 0
Hi, I was wondering if I could get some help. I'm basically writing a script that allows an administrator to give members of a website access to certain areas. The script is a basic Form with radio buttons giving the option to Allow or Deny access.

PHP Code:
<form method="POST" action="update.php">

<?

include "config.inc.php";

mysql_connect($domain,$MySQLusername,$MySQLpassword);
@
mysql_select_db($database) or die( "Unable to select database");
$sql mysql_query("SELECT * FROM users WHERE memberof = 'The Buddhist Fist' AND auth = 'FALSE'");
$fetch mysql_fetch_array($sql);
$totalmembers mysql_num_rows($sql);


$i=0;
while (
$i $totalmembers) {


$approval_id=mysql_result($sql,$i,"id");
$approval_member=mysql_result($sql,$i,"gcharacter");


echo 
"
$approval_member
<br>Approve<label><input name=\"ID['
$approval_id']\" type=\"radio\" value=\"Approve\"></label>
<br>Deny<label><input name=\"ID['
$approval_id']\" type=\"radio\" value=\"Deny\"></label>
<br>Pend<label><input name=\"ID['
$approval_id']\" type=\"radio\" value=\"Pend\" checked></label>
<br>
<br>"
;

$i++;
}

?>

<input type="submit" value="Submit">
</form>

The problem is, I have no idea how to update multiple records like this!
I pretty much want my Update script to change the Auth record in MySQL to TRUE, FALSE or PEND (depending on which button was selected).

Can anyone give me an example of how my Update.php should look?

Any help would be much appreciated! Thanks
Monkeon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-30-2005, 06:03 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Yeah, i don't understand why you've gotten no reply on this.

Radio buttons work just like the text field will in PHP, so there is nothing very complicated about it. PHP will place whatever the radio name and value is into the $_POST array, once the form has been submitted, ignoring the values not selected. So in your case, the Radio is called "ID103883" or whatever number goes after the ID bit, and lets say the user selected "true", to call this in PHP, we simply use $_POST['ID103883']

This variable calls, from the $_POST array (because you've used the POST method on your form, not GET) whatever value is associated with the key "ID103883".

I take it you know the SQL code for this? You'll also need to include the member ID in a hidden input somewhere in the HTML, otherwise you won't be able to identify where to update the database, and mySQL will cry.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-30-2005, 09:06 AM Thanks! I got it working!
Monkeon's Avatar
Skilled Talker

Posts: 59
Trades: 0
Thank you so much for your help.
As soon as you said about the hidden field I instantly knew how I was going to do it.

I made a some minor changes to my form
PHP Code:
<input type=\"hidden\" name=\"id[$approval_id]\" value=\"$approval_id\">
<br>Approve<label><input name=\"OptionID[
$approval_id]\" type=\"radio\" value=\"Approve\"></label> 
<br>Deny<label><input name=\"OptionID[
$approval_id]\" type=\"radio\" value=\"Deny\"></label> 
<br>Pend<label><input name=\"OptionID[
$approval_id]\" type=\"radio\" value=\"Pend\" checked></label> 

Then I made the following Update script


PHP Code:
<?

include "config.inc.php";

$OptionID=$_POST['OptionID'];
$id=$_POST['id'];


// Connect to MySQL
mysql_connect($domain,$MySQLusername,$MySQLpassword);
@
mysql_select_db($database) or die( "Unable to select database");


/*Now Loop through entries and update checked ones*/

foreach ( $id as $memberid ) {

$Grant=$OptionID[$memberid];

echo 
"$memberid -----  $Grant <br>";

$query="UPDATE users SET auth='$Grant' WHERE id='$memberid'";
mysql_query($query);


}

mysql_close();

?>

And it works a treat!
I decided to get rid of the idea of having TRUE, FALSE & PEND in my table. So now it just updates with Approve, Deny and Pend.

Thanks a lot for your help!
Monkeon is offline
Reply With Quote
View Public Profile
 
Old 04-30-2005, 09:26 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
My god, the one time my advise work first time!

It's nice to see someone actually telling us if it worked and saying thanks!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Updating several records with Radio Buttons
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24738 seconds with 12 queries