PHP - Get Data From Database To A Radio Button
I have page with male female radio button
Here's the code Code: [Select] $qry=mysql_query("SELECT * FROM reg_table where id=$id "); $res=mysql_fetch_array($qry); $radio = $res['gender']; switch($radio) { case "male": $mal = "checked"; break; case "female": $fem = "checked"; break; } Code: [Select] Gender: <br /> <input type="radio" name="colour" value="male" checked="<?php $mal; ?>" />Male <input type="radio" name="colour" value="female" checked="<?php $fem; ?>" />Female Whats the use of checked in <input type="radio" name="colour" value="male" checked="<?php $mal; ?>" /> Similar TutorialsWhen I display the data in my database I have included a radio button in each row. When the button is clicked, the intention is to delete all the information in that row. But it won't delete anything... Here's the form: Code: [Select] <FORM Method = "POST" action ="update_tee_times.php"> <?php include("opendatabase.php"); $dateID = $_POST[teetimedate]; $result = mysql_query(" SELECT Date, Player1,Player2,Player3,Player4,Player5,Time, IF( TIME(Time) BETWEEN '17:30:00' AND '19:30:00','FFFF66','FFFFFF') AS color FROM Daysheets WHERE Date ='$dateID'"); echo "<h1>"; echo date("l, F d, Y", strtotime($dateID)); echo "</h1>"; echo "<table align=center width=700 border=1>\n"; echo "<th>Clear</th><th>Time</th><th>Player 1</th><th>Player 2</th><th>Player 3</th><th>Player 4</th><th>Player 5</th> <th>M</th><th>W</th><th>G</th>"; $i=0; while($row = mysql_fetch_array( $result )) { $dateID = $row['Date']; $timeID = $row['Time']; echo "<tr>"; echo "<td>"; echo "<input type='radio' name='time1[$i]' value='$timeID'>"; //HERE'S THE RADIO BUTTON echo "</td><td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player1]' name='player1[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player2]' name='player2[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player3]' name='player3[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player4]' name='player4[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player5]' name='player5[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Men]' name='women' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Women]' name='women' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Guest]' name='guests' style ='background-color:#{$row['color']};'>"; echo "<input type='hidden' name='date[$i]' value='$dateID'>"; echo "<input type='hidden' name='time2[$i]' value='$timeID'>"; echo "</td></tr>"; $i++; } echo "</table>"; mysql_close($con); ?> <br /><br /> <input type="Submit" name="Submit" value="Update Tee Times"> </FORM> And here's the form action: Code: [Select] <?php header("Location: /teetimes/preteetimesadmin.php"); include("opendatabase.php"); $size = count($_POST['player1']); $timeID1 = $_POST['time1'][$i]; //HERE'S WHERE I'M TRYING TO DELETE THE DATA. mysql_query(" UPDATE Daysheets SET Player1='', Player2='', Player3='', Player4='', Player5='' WHERE Time ='$timeID1' "); //HERE'S THE UPDATE, WHICH WORKS FINE. $i=0; while ($i < $size) { $dateID = $_POST['date'][$i]; $timeID2 = $_POST['time2'][$i]; $player1 = ($_POST['player1'][$i]); $player2 = ($_POST['player2'][$i]); $player3 = ($_POST['player3'][$i]); $player4 = ($_POST['player4'][$i]); $player5 = ($_POST['player5'][$i]); mysql_query(" UPDATE Daysheets SET Player1='$player1', Player2='$player2', Player3='$player3', Player4='$player4', Player5='$player5' WHERE Date ='$dateID' AND Time ='$timeID2' "); $i++; } mysql_close($con) ?>When I add or update any information it works fine. It just won't delete anything where the radio button is clicked. Any help appreciated! Thanks. Hi there. I have this course registering website whereby i will need to : 1. pull out all course info and display (done that) 2. when user choose the course they are interested in using radio button and click submit , it will display you're registered and update the database to decrease the head count by 1. i m stuck on the radio button part... after i click submit nothing happens... Please advice... thanks a lot Code: [Select] <html> <head> <title>TimeTable</title> </head> <body> <h1> Here is the timetable</h1> <?php @ $db = new mysqli('localhost', 'root', '', 'mylifestyle'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "SELECT course.CourseName , course.Instructor , course.ClassSize , courseschedule.Date ,courseschedule.Time , courseschedule.Location FROM course INNER JOIN courseschedule ON course.CourseID = courseschedule.CourseID"; $result = $db->query($query); $num_results = $result->num_rows; echo "<table border='1'> <tr> <th>Course Name</th> <th>Instructor</th> <th>Class size</th> <th>Date</th> <th>Time</th> <th>Location</th> <th>Register</th> </tr>"; ?> <?php for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc();?> <tr> <form action = "" method = "post"> <td><? echo $row['CourseName']; ?></td> <td><? echo $row['Instructor']; ?></td> <td><? echo $row['ClassSize']; ?></td> <td><? echo $row['Date']; ?></td> <td><? echo $row['Time']; ?></td> <td><? echo $row['Location']; ?></td> <td align="center"><input name="radio" type="radio" id="radio[]" value="<? echo $row['ClassSize']; ?>"></td> </tr> <?php } ?> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="submit" type="submit" id="submit" value="submit"></td> <?php if($submit){ for($i=0;$i<$num_results;$i++){ $del_id = $radio[$i]; $query = "UPDATE course SET ClassSize = ClassSize -1 Where id='$del_id'"; $result = mysql_query($query); } // if successful redirect to delete_multiple.php if($result){ echo "$CourseName was deleted from database - myliftstyle!!<br />"; // Compute the item costs and total cost } } ?> </div> </body> </html> [attachment deleted by admin] i am developing online test ,after succesful completion of the test i want to display the correct answe,in databse i have stored corect answer as radio button values(ex 1,2,3,4,) i want to display the coreect answer with a right mark,how can i achive this?could anybody help?
here is my code
<?php $testid=$_GET['testid']; include_once("header.php"); ?> <html> <head> <body> <?php include_once('connect.php'); $sqltest="select testname from test where testid='$testid'"; $sqltestresult=mysql_query($sqltest) or die(mysql_error()); while($result=mysql_fetch_array($sqltestresult)) { $testname=$result['testname']; } ?> <!--pass test name and time left --> <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="50%" valign="middle"> <h1 style="margin-left:0;"><?php if(isset($testname)) { echo $testname ; } ?></h1> </td> <td width="50%" align="right" valign="middle"> <ul class="tabs" id="tabs"> <li id="showtime" style="font-weight:bold; color:#FF0000; bottom:5px; font-size:16px; float:right"></li> </ul> </td> </tr></table> <div class="div-tabs-container" class="div-tabs-container" style="width:79%;margin-left:3%" > <table cellpadding="0" cellspacing="0" border="0" id="questiontable" > <tr> <?php include_once('connect.php'); $sql="select * from testquestions where testid='$testid'"; $result=mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result)>0) { $data = array(); // create a variable to hold the information while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false) { $data[] = $row; // add the row in to the results (data) array } //shift off the first value array_shift($data[0]); $merge = call_user_func_array('array_merge', $data); $size=sizeof($merge); $newdata=array(); $num=1; $correctanswerarray=array(); $selctedanswers=array(); /* echo "<form action='fetchquestion.php' method='post' id='formsubmit' onsubmit='return out()' name='test'>"; */ foreach ($merge as $key => $value ) { $sql2="select qid, question,option1,option2,option3,option4,correct_answer from question where qid='$value' "; $result2=mysql_query($sql2) or die(mysql_error()); while($row2=mysql_fetch_assoc($result2)) { $questionid=$row2['qid']; $question=$row2['question']; $option1=$row2['option1']; $option2=$row2['option2']; $option3=$row2['option3']; $option4=$row2['option4']; $correctanswer=$row2['correct_answer']; #array to store the correct answer. $correctanswerarray[] = $questionid.$correctanswer; #$newdata[]=$row2; echo " <table class='bix-tbl-container' cellspacing='0' cellpadding='0' border='0' width='100%' id='questiontable'><tr> <td class='bix-td-qno jq-qno-2413' rowspan='2' valign='top' align='left'>$num</td> <td class='bix-td-qtxt' valign='top'><p>$question</p></td> </tr> <tr> <td class='bix-td-miscell' valign='top'><table class='bix-tbl-options' id='tblOption_2413' border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_A_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='1' id='disable'/> </td><td class='bix-td-option' width='1%'>A.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_A_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option1</td> <td id='tdAnswerIMG_A_2413' class='jq-img-answer' valign='middle'style='display:none;padding-left:10px;'> <img src='/_files/images/website/accept.png' alt='' /> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_B_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='2' id='disabble'/> </td><td class='bix-td-option' width='1%'>B.</td> <td class='bix-td-option' width='48%'id='tdOptionDt_B_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option2</td> <td id='tdAnswerIMG_B_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt=''/> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_C_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='3' id='disable'/> </td><td class='bix-td-option' width='1%'>C.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_C_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option3</td> <td id='tdAnswerIMG_C_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt='' /> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_D_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='4' id='disable'/> </td><td class='bix-td-option' width='1%'>D.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_D_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option4</td> <td id='tdAnswerIMG_D_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt='' /> </td> </tr> </table></td></tr></table> \n <input type='hidden' name='count' value='$num' id='count'> <input type='hidden' name='queId[]' value='$questionid' id='queId'> </td> </tr> </table> "; $num++; } } echo " </tr> </table> "; #array of correct answrer #echo "array of correct answer<br/>"; #print_r($correctanswerarray); #echo "size of the coreect answer array"; $size1=sizeof($correctanswerarray); echo "<br/>"; } else { echo " no questions available for selected test"; } ?> </div> <!-- add div right side --> <div style="height:500px;width:150px;float:right;margin-top:-500px;border:1px solid #99CCFF"> </div> <div style="height:30px"> </div> <!-- add div bottom --> <div style="height:125px;border:1px solid #99CCFF"> </div> <?php include('footer.html'); ?> </body> </html> Edited by mac_gyver, 25 October 2014 - 10:05 AM. code tags around code please The below should choose the radio button that is set by the $_SESSION variable or default to 3. However, it's defaulting to 1. Code: [Select] $content.=' <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1"'; if(isset($review_product_rating) && $review_product_rating=="1"){$content.='checked';} $content.=' /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2"'; if(isset($review_product_rating) && $review_product_rating=="2"){$content.='checked';} $content.=' /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3"'; if(isset($review_product_rating) && $review_product_rating=="3" || !isset($review_product_rating)){$content.='checked';} $content.=' /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4"'; if(isset($review_product_rating) && $review_product_rating=="4"){$content.='checked';} $content.=' /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5"'; if(isset($review_product_rating) && $review_product_rating=="5"){$content.='checked';} $content.=' /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> I'm figuring it's because it's multiple if statement (with no elseif) so it's evaluating the first if and being set to true. I tried changing everything else after the first one to elseif, and it's throwing an unexpected T_ELSEIF error. I'm in the process of making a network for investors and entrepreneurs. When they access their profile page, select edit and go to editprofile.php a problem arises with the data base submission. I have the data they have previously inputted being echoed back out to the user. This lets the user see what they have inputted so that they can make changes to their profile. Unfortunately, with my radio buttons, if no changes are made and the user hits submit, the radio buttons return a value of 'unchecked'. I need them to maintain the value previously submitted to the database if the radio button isn't 'checked'. I'm not sure exactly how to do this. You can test it out yourself by going to http://network.jasonbiondo.com Code is below: Code: [Select] ?php session_start(); require ('connect.php'); include ('header.php'); $savechanges = $_POST['savechanges']; $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strtolower(strip_tags($_POST['username'])); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $entrepreneur = 'unchecked'; $investor = 'unchecked'; $date = date("Y-m-d"); $companyname = strip_tags($_POST['companyname']); $companywebsite = strip_tags($_POST['companywebsite']); $founder = strip_tags($_POST['founder']); $phone = strip_tags($_POST['phone']); $address = strip_tags($_POST['address']); $city = strip_tags($_POST['city']); $state = strip_tags($_POST['state']); $zipcode = strip_tags($_POST['zipcode']); $country = strip_tags($_POST['country']); $development = strip_tags($_POST['development']); $capitalamount = strip_tags($_POST['capitalamount']); $companydo = strip_tags($_POST['companydo']); $founderbuilt = strip_tags($_POST['founderbuilt']); $whatsnew = strip_tags($_POST['whatsnew']); $understand = strip_tags($_POST['understand']); $competition = strip_tags($_POST['competition']); $money = strip_tags($_POST['money']); $demo = strip_tags($_POST['demo']); $incorporation = strip_tags($_POST['incorporation']); $companynameinv = strip_tags($_POST['companynameinv']); $phoneinv = strip_tags($_POST['phoneinv']); $addressinv = strip_tags($_POST['addressinv']); $cityinv = strip_tags($_POST['cityinv']); $stateinv = strip_tags($_POST['stateinv']); $zipcodeinv = strip_tags($_POST['zipcodeinv']); $countryinv = strip_tags($_POST['countryinv']); $angel = strip_tags($_POST['angel']); $vc = strip_tags($_POST['vc']); $capital = strip_tags($_POST['capital']); if ($savechanges) { $queryreg = mysql_query("UPDATE users SET `firstname` = '$firstname', `lastname` = '$lastname', `email` = '$email', `entrepreneur` = '$entrepreneur', `investor` = '$investor', `companyname` = '$companyname', `companywebsite` = '$companywebsite', `founder` = '$founder', `phone` = '$phone', `address` = '$address', `city` = '$city', `state` = '$state', `zipcode` = '$zipcode', `country` = '$country', `development` = '$development', `capitalamount` = '$capitalamount', `companydo` ='$companydo', `founderbuilt` = '$founderbuilt', `whatsnew` = '$whatsnew', `understand` = '$understand', `competition` = '$competition', `money` = '$money', `demo` = '$demo', `incorporation` = '$incorporation', `companynameinv` = '$companynameinv', `phoneinv` = '$phoneinv', `addressinv` = '$addressinv', `cityinv` = '$cityinv', `stateinv` = '$stateinv', `zipcodeinv` = '$zipcodeinv', `countryinv` = '$countryinv', `angel` = '$angel', `vc` = '$vc', `capital` = '$capital' WHERE username= '" . $_SESSION['username'] . "' "); $selected_radio_selector = $_POST['selector']; $selected_radio_invtype = $_POST['invtype']; if ($selected_radio_selector == 'entrepreneur') { $entrepreneur = 'checked'; } else if ($selected_radio_selector == 'investor') { $investor = 'checked'; if ($selected_radio_invtype == 'angel') { $angel = 'checked'; $vc = 'unchecked'; } else if ($selected_radio_invtype == 'vc') { $vc = 'checked'; $angel = 'unchecked'; } else { die("Please select what type of investor you are!"); } } } $q = mysql_query("SELECT `firstname`, `lastname`, `firstname`, `lastname`, `email`, `entrepreneur`, `investor`, `companyname`, `companywebsite`, `founder`, `phone`, `address`, `city`, `state`, `zipcode`, `country`, `development`, `capitalamount`, `companydo`, `founderbuilt`, `whatsnew`, `understand`, `competition`, `money`, `demo`, `incorporation`, `companynameinv`, `phoneinv`, `addressinv`, `cityinv`, `stateinv`, `zipcodeinv`, `countryinv`, `angel`, `vc`, `capital` FROM `users` WHERE username= '" . $_SESSION['username'] . "'"); $r = mysql_fetch_assoc($q); ?> <script type="text/javascript" src="../assets/js/editprofile.js"></script> <form action='editprofile.php' method="POST" id="form"> <fieldset> <p id="required"> * Required Fields</p> <p class="fieldSpacing"> <label for="firstname" class="leftcolalign">First Name *</label> <input id="firstname" class="rightcolalign" name="firstname" value='<?php echo $r['firstname']; ?>'/> </p> <p class="fieldSpacing"> <label for="lastname" class="leftcolalign">Last Name *</label> <input id="lastname" class="rightcolalign" name="lastname" value='<?php echo $r['lastname'];?>'/> </p> <p class="fieldSpacing"> <label for="username" class="leftcolalign">User Name *</label> <?php echo $_SESSION['username']; ?> </p> <p class="fieldSpacing"> <label for="email" class="leftcolalign">Email *</label> <input id="email" class="rightcolalign" name="email" value='<?php echo $r['email']; ?>''/> </p> <p class="fieldSpacing"> <label for="selector" class="leftcolalign">What am I? *</label> <input id="entButton" class="radioalign" type="radio" name="selector" value="entrepreneur"<?php echo $r['entrepreneur']; ?>/> <label for="entrepreneur" id="entrepreneur">Entrepreneur</label> <input id="invButton" class="radioalign" type="radio" name="selector" value="investor"<?php echo $r['investor']; ?>/> <label for="investor" id="investor">Investor</label> </p> </fieldset> <fieldset id="entForm"> <p class="fieldSpacing"> <label for="companyname" class="leftcolalign">Company Name: *</label> <input id="companyname" class="rightcolalign" name="companyname" value='<?php echo $r['companyname']; ?>'/> </p> <p class="fieldSpacing"> <label for="companywebsite" class="leftcolalign">Company Website:</label> <input id="companywebsite" class="rightcolalign" name="companywebsite" value='<?php echo $r['companywebsite']; ?>'/> </p> <p class="fieldSpacing"> <label for="founder" class="leftcolalign">Founder(s): *</label> <input id="founder" class="rightcolalign" name="founder" value='<?php echo $r['founder']; ?>'/> </p> <p class="fieldSpacing"> <label for="phone" class="leftcolalign">Phone Number(s): *</label> <input id="phone" class="rightcolalign" name="phone" value='<?php echo $r['phone']; ?>'/> </p> <p class="fieldSpacing"> <label for="address" class="leftcolalign">Address: *</label> <input id="address" class="rightcolalign" name="address" value='<?php echo $r['address']; ?>'/> </p> <p class="fieldSpacing"> <label for="city" class="leftcolalign">City: *</label> <input id="city" class="rightcolalign" name="city" value='<?php echo $r['city']; ?>'/> </p> <p class="fieldSpacing"> <label for="state" class="leftcolalign">State:</label> <input id="state" class="rightcolalign" name="state" value='<?php echo $r['state']; ?>'/> </p> <p class="fieldSpacing"> <label for="zipcode" class="leftcolalign">Zip Code:</label> <input id="zipcode" class="rightcolalign" name="zipcode" value='<?php echo $r['zipcode']; ?>'/> </p> Hey in my edit page i have 2 radio buttons in my form and i need to make sure the same value is still selected how can i do that? thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321339.0 Is there anyway of saving data to phpmyadmin, and linking it to another page with one button. I can do it separately but I can't seem to do it using one button. Does anyone has any ideas! 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 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 Hi, I have 2 radio button's within a table and need to pass this array. All other rows within my table can be sent as array's and captured using $_POST['field_name'][$ROW 1 value etc]. However for radio buttons this doesn't work. As an example, a standard textbox I can send an array using the following: echo "<td width='33%'><input type='Textbox' width='100%' id='test' name='test[]' value='" .$row['test']. "'></td>"; I can then capture it using: $test = $_POST['test'][$iLine]; This works, no problem, however for radio buttons, I can't use a static array name, as presumably it dumps all rows into the array, if I do this, only the last row has a checked button, hence I need to use the following (where $checked includes the logic to decide whether the button should be checked or not, this works correctly): echo "<input type='radio' name='".$row['venue_id']."[]' value='1'".$checked."/>P1" echo "<input type='radio' name='".$row['venue_id']."[]' value='0'".$checked2." />P2"; I tried using the following: var_dump($_POST[$row]['game_id'][$iLine]); But this just returns a null value. Any ideas? how do you make it so that a radio button is either checked or unchecked based on database? 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 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. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=346803.0 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 |