PHP - Saving Radio Button Values
i have an rsvp page where the table is populated by guests according to event selected in the drop down list. the rsvp table has 2 columns: guest names and status. status(radio button) is divided into 3: unconfirmed(default status), attending and not attending. user has to choose either one. but i am having trouble saving the status. tia for any help!
this is the saving code:
<?php if(isset($_SESSION['sess_user_id'])) { if(isset($_POST['save-rsvp'])) { require "connection.php"; $name = $_POST['name']; $radio = $_POST['rsvp']; $session = $_SESSION['sess_user_id']; $rsvp = $dbh->prepare("UPDATE guest SET status = ? WHERE guser_id = ? AND guest_name = ?"); $rad = implode("','", $radio); for($i = 0; $i < count($_POST['name']); $i++) { if(trim($_POST['name'][$i]) !== '')// validate this form { $rsvp->bindParam(1, $rad, PDO::PARAM_INT); $rsvp->bindParam(2, $session, PDO::PARAM_INT); $rsvp->bindParam(3, $name[$i], PDO::PARAM_STR); $rsvp->execute(); } } } } ?>which when save doesn't save according to status selected. for example 5 names: noreen, pete, marzuki, nora, mishal noreen unconfirmed pete attending marzuki attending nora attending mishal not attending micah not attending when saved, all is saved as unconfirmed. noreen not attending pete attending marzuki not attending nora attending mishal not attending micah attending when saved, all is saved as not attending. noreen attending pete not attending marzuki attending nora not attending mishal attending micah not attending when saved, all is saved as attending. it seems to save according to first choice. Similar TutorialsI am having some difficulty with accessing radio button values with PHP code. Please see the attached file
Attached Files
x.txt 530bytes
11 downloads Hello! I am designing a user registration form which has some radio buttons for people to select. I am confused as to how I should store the value selected by the user into the database. Here is my code, just in case. <li id="li_2" > <label class="description" for="element_2">I am a </label> <span> <input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" /> <label class="choice" for="element_2_1">Student</label> <input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" /> <label class="choice" for="element_2_2">Staff</label> <input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" /> <label class="choice" for="element_2_3">Member</label> <input id="element_2_4" name="element_2" class="element radio" type="radio" value="4" /> <label class="choice" for="element_2_4">Other</label> </span> </li> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=350049.0 Hi guys, I am having a real problem with this and I can't figure it out. I am not that much of a techie so take it easy on me. I am building a survey form for a website to get feedback on the service, and naturally it can fail validation if the email address is misspelled or the security question is answered wrong. Retaining text values was easy and I managed to dig around for some solutions to retain radio button values. The problem is IT ONLY WORKS ON ONE OPTION! I tried everything including coming up with completely separate value names, yet the page still loads with all radio options set to the same shared value (usually of the last radio button question). Here is my code: <?PHP $Excellent_status = 'unchecked'; $VeryGood_status = 'unchecked'; $Satisfactory_status = 'unchecked'; $Weak_status = 'unchecked'; $Horrible_status = 'unchecked'; if (isset($_POST['send'])) { $selected_tk = $_POST['tk']; if ($selected_tk == 'Excellent') { $Excellent_status = 'checked'; } else if ($selected_tk == 'VeryGood') { $VeryGood_status = 'checked'; } else if ($selected_tk == 'Satisfactory') { $Satisfactory_status = 'checked'; } else if ($selected_tk == 'Weak') { $Weak_status = 'checked'; } else if ($selected_tk == 'Horrible') { $Horrible_status = 'checked'; } } $Excellent2_status = 'unchecked'; $VeryGood2_status = 'unchecked'; $Satisfactory2_status = 'unchecked'; $Weak2_status = 'unchecked'; $Horrible2_status = 'unchecked'; if (isset($_POST['send'])) { $selected_ts = $_POST['ts']; if ($selected_ts == 'Excellent') { $Excellent2_status = 'checked'; } else if ($selected_ts == 'VeryGood') { $VeryGood2_status = 'checked'; } else if ($selected_ts == 'Satisfactory') { $Satisfactory2_status = 'checked'; } else if ($selected_ts == 'Weak') { $Weak2_status = 'checked'; } else if ($selected_ts == 'Horrible') { $Horrible2_status = 'checked'; } } ?> <h1 align="center">Feedback Form:</h1> <p align="center">We highly value your input. Your feedback can help us serve you better and provide you with a holistic experience that meets or exceeds all your expectations. <br /> Please take the time to fill out the form below.</p> <br /> <br /> <p align="center"><strong>(Fields marked with a <span class="required">*</span> are necessary. The course information is to validate which course and batch the survey is regarding, and the name and email allows our admin to verify the details and gain more information from you if needed)</strong></p> <p align="center"><strong>The identity in this form is strictly confidential, and it will not be revealed to course trainer, co-ordinator, or your sponsor.</strong></p> <!--Error Message--> <?php echo $error;?> <form method="post" name="contFrm" id="contFrm" action=""> <label><span class="required">*</span>Name:</label> <input name="name" type="text" class="box" id="name" size="40" value="<?php echo $name;?>" /><br /> <label><span class="required">*</span>Email: </label> <input name="email" type="text" class="box" id="email" size="40" value="<?php echo $email;?>" /><br /> <label><span class="required">*</span>Course attended: </label> <input name="course" type="text" class="box" id="course" size="40" value="<?php echo $course;?>" /><br /> <label><span class="required">*</span>Course Date and City: </label> <input name="dateplace" type="text" class="box" id="dateplace" size="40" value="<?php echo $dateplace;?>" /><br /><br /><br /> <table width="980" border="1" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="280" align="left" bgcolor="#285A80"><strong><font color="#FFFFFF" size="+1">Attribute</font></strong></td> <td width="115"> <div align="center">EXCELLENT! </div></td> <td width="115"> <div align="center">Really Good. </div></td> <td width="115"> <div align="center">Satisfactory. </div></td> <td width="115"> <div align="center">Weak, needs attention. </div></td> <td width="115"> <div align="center">Horrible! Unacceptable. </div></td> </tr> <tr> <td width="280" align="left" bgcolor="#71C4CD"><strong><font color="#333333">Trainer Knowledge</font></strong></td> <td> <div align="center"> <input type="radio" name="tk" id="Excellent" value="Excellent" <?PHP print $Excellent_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="tk" id="VeryGood" value="VeryGood" <?PHP print $VeryGood_status; ?>/> </div> </label></td> <td> <div align="center"> <input type="radio" name="tk" id="Satisfactory" value="Satisfactory" <?PHP print $Satisfactory_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="tk" id="Weak" value="Weak" <?PHP print $Weak_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="tk" id="Horrible" value="Horrible" <?PHP print $Horrible_status; ?>/> </div> </td> </tr> <tr> <td width="280" align="left" bgcolor="#71C4CD"><strong><font color="#333333">Trainer Style and Presentation</font></strong></td> <td> <div align="center"> <input type="radio" name="ts" id="Excellent2" value="Excellent2" <?PHP print $Excellent2_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="ts" id="VeryGood2" value="VeryGood2" <?PHP print $VeryGood2_status; ?>/> </div> </label></td> <td> <div align="center"> <input type="radio" name="ts" id="Satisfactory2" value="Satisfactory2" <?PHP print $Satisfactory2_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="ts" id="Weak2" value="Weak2" <?PHP print $Weak2_status; ?>/> </div> </td> <td> <div align="center"> <input type="radio" name="ts" id="Horrible2" value="Horrible2" <?PHP print $Horrible2_status; ?>/> </div> </td> </tr> </table> <br /><br /> <label>Particularly positive points you appreciated: </label> <textarea name="message1" cols="80" rows="3" id="message1"><?php echo $message1;?> </textarea><br /> <label>Particularly negative points you found disappointing: </label> <textarea name="message2" cols="80" rows="3" id="message2"><?php echo $message2;?> </textarea><br /> <label>Any specific message you would like to provide us: </label> <textarea name="message3" cols="80" rows="3" id="message3"><?php echo $message3;?> </textarea><br /> <label><span class="required">* Security Question</span></label><? require_once ("ClassMathGuard.php"); MathGuard::insertQuestion(); ?> <br /> <br /> <!-- Submit Button--> <input name="send" type="submit" class="button" id="send" value="" /> </form> Fact is there are 8 questions (all multiple choice with radio button answers) but I decided to save you a long code read. Basically what I get is that despite choosing different answers for each question, the retention is only of the last option or question, and all the above question choices are set to that choice button. What is wrong? I want to save class property values and want to write these in the database after being called from another function. Code: [Select] class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); public function insert_data() { $sql = "INSERT INTO account VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; //if(isset($data)) echo $sql; } public function data_approoved($user){ //$user_info = new array(); $user_arr['username'] = $user['username']; $user_arr['password'] = $user['password']; $user_arr['email'] = $user['email']; $user_arr['location'] = $user['location']; $user_info['interests'] = $user['interests']; $user_info['homepage'] = $user['homepage']; Model::insert_data(); } } }//class ended The approoved_data function is supposed to set the values of $user_info array which should be later on stored in database. Please somebody help me. I have figured out far enough to loop through my table and return a list of check boxes that will be matched to a product. My issue now, is i cannot figure out the proper way to loop through them after they are selected and return them as checked/unchecked for the given product. Thought there is some MySQL involved, that part isn't the problem, I know how to insert into a database or update...when the product is selected from a drop down, I need to be able to populate the checkboxes. Here is the code i am using to initially display all of the categories to choose from... <ul class="categories"> <?php $query = "SELECT * FROM products"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $category = $row['category']; $catId = $row['id']; echo "<li><input class='catCheck' type='checkbox' name='p_cat[]' value='$catId' /> $category</li>"; } ?> </ul> Thanks guys.... Hey guys, I need your help on this please. I am working on a php web application. I have a form that gets information for Supplier and his traveling details. The values are stored in arrays. I would like to store supplier details in Supplier table and the travelling details in the Travel table. Here is the code with the comments. <?php if (isset($_VARS['submitSuppliers'])) { //error checking starts here $isError = false; if (empty($_VARS['supplierName'])) { $isError = true; $_VARS['supplierRequest']['supplierName']['errorMessage'] = 'You need to provide a Supplier Name.'; } if (empty($_VARS['address'])) { $isError = true; $_VARS['supplierRequest']['address']['errorMessage'] = 'You need to provide an Address.'; } if (empty($_VARS['travel'])) { $isError = true; $_VARS['supplierRequest']['city']['errorMessage'] = 'You need to provide travelling details.'; } #this checks if there is no error and then proceeds to save form values if (!$isError) { #This function adds the details and Returns the autoincremented Supplier ID $SupId = add_suppliers($_VARS); if ($SupId) { #=== Now here I would like to save the travelling details in the Travel table using the generated supplier id # $travId = add_Travel($_VARS); //==== how do I segregate only travel details from the $_VARS array to store in travel table? REDIRECT('/supplier/index.html', array('confirmationMessage' => 'Your details have been saved.')); }else { notify_admin('supplierjoin.php'); } }else { $_VARS['supplierRequest']['errorMessage'] = "There was a problem with the information you provided. Please check the form and try again."; } } ?> Kindly help. Any comment or feedback is always welcome. Thank you I have a form that contains radio buttons and when it is submitted the content of the form are added to a database. I was wondering how you get the values of radio boxes when submitting the form. I have the following radio buttons and when submitting I use "$_POST['article_type']" but this doesn't seem to work. Thanks for any help. <label>PDF Article</label><input name="article_type" value="pdf" type="radio" /> <label>Video Webcast</label><input name="article_type" value="webcast" type="radio" /> <label>Podcast</label><input name="article_type" value="podcast" type="radio" /> Hey Guys. I have a quick question. Should i "prep" input values coming from a radio or checkbox input field? Can an SQL injection occur through those 2 input fields, or is it only text fields?
I have several radio buttons (dynamically generated) and I want to use the selected value in a MySql query WHERE clause. Is it possible? Hello, I had 3 radio buttons with the same name, well, I had created 3 text box that are next to those 3 radio buttons. When I click save to the form, I need to know which radio button had been pressed, so that I can detect & retrieve its value. Any help? Thanks What am I doing wrong with this selected radio button? <form action="Process/privacy.php" method="post" enctype="multipart/form-data" id="privacy"> <div id="privacy_vis">Your profile is visible to:</div> <div id="privacy_select"> <label> <input name="RadioGroup1" type="radio" id="RadioGroup1_0" value="1" <?if($visible=="1")echo 'checked="checked"';?> /> Everyone</label> <label> <input name="RadioGroup1" type="radio" id="RadioGroup1_1" value="0"/> Members Only</label> </div> <br /> <div id="privacy_vis">Your Password to view your private pictures is:</div> <div> <input name="pictures_pw" type="text" id="pictures_pw" value="<? echo "$xxx_pw" ?>" size="50" maxlength="20" /> </div> <br /> <div> <input name="submit" type="submit" class="button" id="submit" value="Save Changes" /> </div> </form> </div> I have a function to display some images and allow a user to select a choice via a radio button.The value is then passed to another function. I have 2 problems My selection is not being passed back and I cant assign the value to a query sring in a link to another page. On the form do i need to add checked? Any help appreciated. Code: [Select] function cover() { echo'<h2>Please upload your book cover or choose one from the selection</h2> <p>All book ideas require a cover. Your choice can be changed at a later date.</p>'; //process selection of cover if (isset($_POST['submit'])) { $coverID=$_POST['cover']; echo $coverID; ?>   <ul><li class="demo-menu-link"><a href="?page=submenu7&coverID=$coverID">Finnished Cover</a></li></ul><?php exit(); } else{ echo "not Submitted"; } global $wpdb; $query = "select * from wp_cover"; $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result){ return false; } echo'<div class="wrap"><p>choose from one of the covers below</p></div>'; ?><form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" id="cover" enctype="multipart/form-data"> <table><tr><?php /* display picture and radio button */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $coverID=$row['coverID']; echo"<img src=\"/wordpress_3/wp-content/plugins/Authors2/jackets/{$row['pix']}\" />"; echo"<td>"; echo $coverID; echo "<Input type = 'Radio' Name ='cover' value= '$coverID'/>"; ?> </tr></table> <input type=submit value=submit> </form><?php } } I am trying to have the text alongside the radio button trigger the radio button (cannot use < a href ) e.g. () Trigger with this text The closest I have found is <label for="r1"><input type="radio" name="group1" id="r1" value="1" /> button one</label> But it does not seem to work? Any help greatly appreciated how do you make it so that a radio button is either checked or unchecked based on database? I am trying to make a set of radio buttons that when you make a selection, it displays a sorted database from MYSQL. I have the MYSQL part figured out but I cannot figure out how to properly display it. I have the following code and I made a select screen just to test: index.html <html> <body> <form action="select.php" method="post"> <input type="radio" name="table" value="table1"> Table 1 <br> <br> <input type="radio" name="table" value="table2">Table 2 <br> <br> <input type="radio" name="table" value="table3">Table 3 <br> <br> <input type="radio" name="table" value="table4">Table 4 <br> <br> <input type="radio" name="table" value="table5">Table 5 <br> <br> <input type="Submit" Name = "submit" value="Submit"> <input type="Reset" value="Reset"> </form> </body></html> select.php <?PHP $selected_radio = $_POST["table"]; if ($selected_radio = = 'table1) { echo "Table 1 Here."; } else if ($selected_radio = = 'table2') { echo "Table 2 Here."; } else if ($selected_radio = = 'table3') { echo "Table 3 Here."; } else if ($selected_radio = = 'table4') { echo "Table 4 Here."; } else if ($selected_radio = = 'table5') { echo "Table 5 Here."; } ?> These are two separate files. When I go to run the code, no matter what I pick, the next page is always blank. Again, the select.php is just suppose to be a check, the real code will display the table instead of echoing a message. Good Day, I juz like to know if there any other alternative way for the code below, coz i can't update my form when i use this method for radio the button. It's not passing the value. Code: [Select] Edit.php <tr> <td height="36" align="center" valign="middle" bgcolor="#990000"><div align="left" class="style4">Destroy :</div></td> <td align="center" valign="middle" bgcolor="#990000"><div align="left"> <label> <input type=radio name=destroyR value="Yes" <?php echo ($rows['destroy']=='Yes') ?'checked="checked"':''; ?> />Yes</label> <label> <input type=radio name=destroyR value="No" <?php echo ($rows['destroy']=='No') ?'checked="checked"':''; ?> />No</span></label> </div></td> </tr> i would like to display the value of the selected radio button on the same page... what i want is just reload the page and if there is a radio button selected displays it but i cant display it <?PHP if (isset($_GET["submit"])) { echo $_GET["myradio"]; } ?> <html> <head> </head> <body> <form action="<?PHP $_SERVER["PHP_SELF"]; ?>" method="get"> One <input type="radio" name="myradio" value="one"> Two <input type="radio" name="myradio" value="two"> <a href="<?PHP $_SERVER["PHP_SELF"]; ?>" name="submit">test </a> </form> </body> </html> please help guys...thanks This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=317717.0 I have a group of 4 radio buttons. my mysql database knows which one the user selected previously when they stored some information. I now wish to display the same buttons but have radio button checked that the user chose before. I know this can be done but having one of those mind melt moments where I cannot think of the solution so I have 4 buttons that look like this Code: [Select] <input type="radio" name="clarity" id="clarity" value="Opaque"> Opaque<br> <input type="radio" name="clarity" id="clarity" value="Deep"> Deep<br> <input type="radio" name="clarity" id="clarity" value="Mid"> Mid<br> <input type="radio" name="clarity" id="clarity" value="Pale"> Pale<br></td> I just need to attached a checked field to the correct item |