PHP - Radio Button Validation Not Running
Similar TutorialsHi 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 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 } } 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> 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 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 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=317717.0 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 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 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. 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 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? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=346803.0 <?php $goal = rand(1, 3); ?> <td><div align="left"> Goal</div></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio2" value="1" <?php if($goal == "1") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input name="goal_chk" type="radio" id="radio13" value="2" <?php if($goal == "2") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio23" value="3" <?php if($goal == "3") { echo "checked"; }?> /> </div> </label></td> </tr> i have a group of radio buttons whose value is checked randomly everytime you refresh the page, now that works fine, everytime you refresh the page the checked values moves randomly but the problem i have is getting the actual of a checked radio button. i have tried this... $goal_checked = $_POST['goal_chk']; echo $goal_checked; But nothing happens. Any ideas on how to make this possible. Thanks a lot you guys. 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; ?>" /> Hello, I have a simple PHP form that sends the results as a message to my email address. The form is composed only of text areas and text fields. All works well until I try to introduce radio buttons. When I get the message the result is blank. This is the form: <form id="contact-form" name="contact-form" method="post" action="submit.php"> <table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <td><label for="name">Your Name:</label></td> <td><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td> <td id="errOffset"> </td> </tr> <tr> <td><label for="email">Your Email Address:</label></td> <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> <td> </td> </tr> <tr> <td valign="top"><label for="message">How can we help you</label></td> <td><textarea name="message" id="message" cols="35" rows="3"><?=$_SESSION['post']['message']?></textarea></td> <td valign="top"> </td> </tr> <tr> <td><label for="contact">Preferred method of contact:</label></td> <td> <label class="second" for="contact">By Email:</label><input name="<?=$_SESSION['post']['contact']?>" id="contact-email" type="radio" value="Email" checked /> <label class="second" for="contact">By Phone:</label><input name="<?=$_SESSION['post']['contact']?>" id="contact-phone" type="radio" value="Phone" /> </td> <td id="errOffset"> </td> </tr> <tr> <td><label for="captcha">Security Question: <?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td> <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td> <td valign="top"> </td> </tr> <tr> <td valign="top"> </td> <td colspan="2"><input type="submit" name="button" id="button" value="Submit" /> <input type="reset" name="button2" id="button2" value="Reset" /> <?=$str?> <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td> </tr> </table> </form> <?=$success?> And this is the submit.php file it refers to: <?php /* config start */ $emailAddress = 'email@gmail.com'; /* config end */ require "phpmailer/class.phpmailer.php"; session_name("fancyform"); session_start(); foreach($_POST as $k=>$v) { if(ini_get('magic_quotes_gpc')) $_POST[$k]=stripslashes($_POST[$k]); $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k])); } $err = array(); if(!checkLen('name')) $err[]='The name field is too short or empty!'; if(!checkLen('email')) $err[]='The email field is too short or empty!'; else if(!checkEmail($_POST['email'])) $err[]='Your email is not valid!'; if((int)$_POST['captcha'] != $_SESSION['expect']) $err[]='The captcha code is wrong!'; if(count($err)) { if($_POST['ajax']) { echo '-1'; } else if($_SERVER['HTTP_REFERER']) { $_SESSION['errStr'] = implode('<br />',$err); $_SESSION['post']=$_POST; header('Location: '.$_SERVER['HTTP_REFERER']); } exit; } $msg= 'Name: '.$_POST['name'].'<br /> Email: '.$_POST['email'].'<br /> Message: '.$_POST['message'].'<br /> Contact by: '.$_POST['contact'].' '; $mail = new PHPMailer(); $mail->IsMail(); $mail->AddReplyTo($_POST['email'], $_POST['name']); $mail->AddAddress($emailAddress); $mail->SetFrom($_POST['email'], $_POST['name']); $mail->Subject = "Contact Form"; $mail->MsgHTML($msg); $mail->Send(); unset($_SESSION['post']); if($_POST['ajax']) { echo '1'; } else { $_SESSION['sent']=1; if($_SERVER['HTTP_REFERER']) header('Location: '.$_SERVER['HTTP_REFERER']); exit; } function checkLen($str,$len=2) { return isset($_POST[$str]) && strlen(strip_tags($_POST[$str])) > $len; } function checkEmail($str) { return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str); } ?> These are the 2 files I've been updating. I'm definitely not good at PHP so any help cracking this problem would be welcome. Thank you. <?php $SQL = "SELECT stu_satisfaction_tblquestions.question_id, stu_satisfaction_tblquestions.question, answer_type.* FROM stu_satisfaction_tblquestions LEFT JOIN answer_type ON stu_satisfaction_tblquestions.answers_id=answer_type.answers_id WHERE stu_satisfaction_tblquestions.answers_id BETWEEN '1' AND '2' "; $result = mysql_query($SQL); while ($data = mysql_fetch_array($result)) { echo $data['question'].'<br/>'; echo '<input type="radio" name="answers['.$data['question_id'].']" id="'.$data['question_id'].'_'.$data['answer1'].'" value="1" /><label for="'.$data['question_id'].'_'.$data['answer1'].'">'.$data['answer1'].'</label><br/>'; echo '<input type="radio" name="answers['.$data['question_id'].']" id="'.$data['question_id'].'_'.$data['answer2'].'" value="2" /><label for="'.$data['question_id'].'_'.$data['answer2'].'">'.$data['answer2'].'</label><br/>'; echo '<input type="radio" name="answers['.$data['question_id'].']" id="'.$data['question_id'].'_'.$data['answer3'].'" value="3" /><label for="'.$data['question_id'].'_'.$data['answer3'].'">'.$data['answer3'].'</label><br/>'; echo '<input type="radio" name="answers['.$data['question_id'].']" id="'.$data['question_id'].'_'.$data['answer4'].'" value="4" /><label for="'.$data['question_id'].'_'.$data['answer4'].'">'.$data['answer4'].'</label><br/>'; echo '<input type="radio" name="answers['.$data['question_id'].']" id="'.$data['question_id'].'_'.$data['answer5'].'" value="5" /><label for="'.$data['question_id'].'_'.$data['answer5'].'">'.$data['answer5'].'</label><br/>'; } ?> this is my form, how should i validate the radio buttons of it? When 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. <?php
require_once('upper.php'); require_once('LoginStatement.php'); require_once('database.php'); echo $error_msg=''; require_once('database.php'); $LoginId=$_COOKIE['LoginIdCookie']; $query="select * from registration where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query); $row=mysqli_fetch_array($result); if(isset($_POST['submit'])) { $LoginId=mysqli_real_escape_string($dbc,trim($_POST['LoginId'])); $Name=mysqli_real_escape_string($dbc,trim($_POST['Name'])); $Age=mysqli_real_escape_string($dbc,trim($_POST['Age'])); $BloodGroup=mysqli_real_escape_string($dbc,trim($_POST['BloodGroup'])); if(!isset($_POST['Sex'])) { echo 'Please enter Sex<br>'; } else{ $Sex= mysqli_real_escape_string($dbc,trim($_POST['Sex'])); } $Qualification=mysqli_real_escape_string($dbc,trim($_POST['Qualification'])); $ContactNumber=mysqli_real_escape_string($dbc,trim($_POST['ContactNumber'])); $Email=mysqli_real_escape_string($dbc,trim($_POST['Email'])); $Address=mysqli_real_escape_string($dbc,trim($_POST['Address'])); $AboutYourself=mysqli_real_escape_string($dbc,trim($_POST['AboutYourself'])); //$countCheck=count($_POST['checkbox']); //echo $countCheck; //$checkbox=$_POST['checkbox']; //$countCheck=count($checkbox); if(empty($LoginId)){echo 'Please enter Login Id';} elseif(empty($Name)){echo 'Please enter Name';} elseif(empty($Age)){echo 'Please enter Age';} elseif(!isset($_POST['Sex'])){} elseif(empty($Qualification)){echo 'Please enter Qualification';} elseif(empty($ContactNumber)){echo 'Please enter Contact Number';} elseif(empty($Email)){echo 'Please enter Email';} elseif(empty($Address)){echo 'Please enter Address';} elseif(empty($AboutYourself)){echo 'Please enter About Yourself';} else { if(mysqli_num_rows($result)==0) { $checkbox=$_POST['checkbox']; $countCheck=count($_POST['checkbox']); $reg_id=' '; for($i=0;$i<$countCheck;$i++) { $reg_id=$reg_id.$checkbox[$i].','; } $query="UPDATE registration SET (LoginId,Name,Age,BloodGroup,Sex,Qualification,ContactNumber,Email,Address,AboutYourself,Activity)values ('$LoginId',SHA('$Password1'),'$Name','$Age','$BloodGroup','$Sex','$Qualification','$ContactNumber','$Email','$Address','$AboutYourself',',$reg_id')"; $result=mysqli_query($dbc,$query) or die("Not Connect"); echo ' Dear '.$Name.'.<br>Your request has been mailed to admin.<br>Your account is waiting for approval<br>'; $from= 'Elite Brigade'; $to='ankitp@rsquareonline.com'; $subject='New User Registration'; $message="Dear admin,\n\nA new user request for registration. Please check it out.\n\nRegards\nMicro"; mail($to,$subject,$message,'From:'.$from); //header('Location: index.php'); // header('Location: Registration.php'); } else { echo 'Dear '.$Name. ', <br> An account already exist with login-id<b> '.$LoginId.'</b> <br>Please try another login-id'; }} } ?> <html> <head> <script src="jquery-latest.js"></script> <script type="text/javascript" src="jquery-validate.js"></script> <style type="text/css"> * { font-family: Verdana; } label.error { color: white; padding-left: .5em; } p { clear: both; } .submit { margin-left: 12em; } em { font-weight: bold; padding-right: 1em; vertical-align: top; } </style> <script> $(document).ready(function(){ $("#commentForm").validate(); }); </script> </head> <body> <?php echo $error_msg; ?> <form action='<?php echo $_SERVER['PHP_SELF'];?>' id="commentForm" method='post'> <div class="registration_and_activity"> <table border="0" width="380"> <tr><td colspan="2"> <h3>Update Personal Details</h3></td></tr> <tr><td width="120"> <em>*</em>Enter Login id</td><td width="150"><input type='text' name='LoginId' minlength='4' value='<?php echo $row['LoginId']; ?>' /></td></tr> <tr><td width="120"> <em>*</em>Enter Name</td> <td><input type='text' name='Name' value='<?php echo $row['Name'];?>' /></td></tr> <tr><td> <em>*</em>Enter Age</td><HEAD> <SCRIPT language=Javascript> function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </SCRIPT> </HEAD> <td><INPUT onkeypress='return isNumberKey(event)' type='text' name='Age' value='<?php echo $row['Age'];?>'/></td></tr> <tr><td> <em>*</em>Enter Blood</td><td><input type='text' name='BloodGroup' value='<?php echo $row['BloodGroup'];?>' /></td></tr> [B]<tr><td> <em>*</em>Enter Sex</td><td><input type='radio' name='Sex' style='width:16px; border:0;' value='Male' checked='<?php if($row['Sex']='Male') echo 'checked';?>'/>Male <input type='radio' name='Sex' checked='<?php if($row['Sex']='Female') echo 'checked';?>' style='width:16px; border:0;' 'value='Female' />Female</td></tr>[/B] <tr><td> <em>*</em>Enter Qualification</td><td><input type='text' name='Qualification' value='<?php echo $row['Qualification'];?>' /></td></tr> <tr><td> <em>*</em>Contact Number </td><td><input onkeypress='return isNumberKey(event)'type='text' name='ContactNumber' value='<?php echo $row['ContactNumber'];?>' /></td></tr> <tr><td> <em>*</em>Enter Email</td><td><input type='text' name='Email'class="email" value='<?php echo $row['Email'];?>' /></td></tr> <tr><td> <em>*</em>Enter Address</td><td><input type='text' name='Address' value='<?php echo $row['Address'];?>' /></td></tr> <tr ><td > <em>*</em>About Yourself </td></tr> <tr><td colspan="2"><textarea rows='10' cols='40' name='AboutYourself' /><?php echo $row['AboutYourself'];?></textarea></td></tr> <tr><td> <?php echo "<tr><td colspan='2' align='center'><input type='submit' value='Update' name='submit' style='background:url(./images/button_img2.png) no-repeat 10px 0px; width:100px; padding:3px 0 10px 0; color:#FEFBC4; border:0;'/></td></tr><br>"; echo " </td></tr></table> </div> </form> </body> </html>"; require_once('lower.php'); ?> Hi friends.......... In above code I want that In database if Sex=Male then Male radio button will be checked automatically and if Sex =Female then Female radio button will be checked. But it not works ........... please help me........... thanks in advance.......... Hey all, I'm almost too embarrased to post this as I'm sure it is very simple - but for the life of me I can't get this to work. I am a complete newbie to PHP so please bear with me.. What I'm trying to do is to write a program that will go on to calculate a user's Body Mass Index (BMI) based on user inputted data of height and weight. However, I want to be able to accept heights and weights in a number of different units for maximum ease of use. I am trying to write some PHP code that will handle this , the main goal is to convert everything into 'cm' and 'kg' before going on and doing the simple BMI calculation later on. However I am stuck at this point: I have a text field for users to input their weight into. This is immediately followed by two radio buttons for the user to select which units they are inputting their weight in (kilograms or pounds). A third option to input their weight is given after this for those wishing to input their weight in 'stones and pounds'. My problem is as follows: I can't get my code to recognise which radio button (either 'kg' or 'lbs') has been pressed. What should happen is that my code can tell something has been inputted in the text box AND which of the radio buttons has been selected. From this it does one of the two; for the kilogram option it leaves the value as it is, but if the weight has been inputted in pounds (and the 'lbs' radio button selected) then I want the code to convert this into kilos by multiplying by 0.4535. Here is what I have so far (sorry its a bit messy - like i say I am a newbie): <?php //convert.php $ft = $cm = $inches = $weight = $stones =$pounds = $kilos = $units = ""; if(isset($_POST['cm'])) $cm = sanitizeString($_POST['cm']); if(isset($_POST['ft'])) $ft = sanitizeString($_POST['ft']); if(isset($_POST['inches'])) $inches = sanitizeString($_POST['inches']); if(isset($_POST['weight'])) $weight = sanitizeString($_POST['weight']); if(isset($_POST['stones'])) $stones = sanitizeString($_POST['stones']); if(isset($_POST['pounds'])) $pounds = sanitizeString($_POST['pounds']); if(isset($_POST['kilos'])) $kilos = sanitizeString($_POST['kilos']); if(isset($_POST['units'])) $units = sanitizeString($_POST['units']); if ($ft != '') { $height = intval(($ft * 30.48) + ($inches * 2.54)); $out = "you are $height cm tall"; } elseif($cm != '') { $height = intval($cm); $out = "you are $height cm tall"; } else $out = ""; if ($stones != '') { $kilos = intval((($stones * 14) + $pounds) * 0.45359237); $out2 = "you weigh $kilos Kg"; } elseif($weight != '' AND $units = "kg") { $kilos = $weight; $out2 = "you weigh $kilos Kg"; } elseif($weight != '' AND $units = "lbs") { $kilos = ($weight * 0.45359237); $out2 = "you weigh $kilos Kg"; } else $out2 = ""; echo <<<_END <html><head><title>Height & Weight Converter</title> </head><body><pre> Please enter your details below <b>$out$out2</b> <form method="post" action="convert.php"> Height: <input type="text" name="cm" size="3"> cm OR <input type="text" name="ft" size="1">ft <input type="text" name="inches" size="2">inches Weight: <input type="text" name="weight" size="4" /> Kg<input type="radio" name="units" value="kg" /> lbs<input type="radio" name="units" value="lbs" /> OR <input type="text" name="stones" size="2">stone <input type="text" name="pounds" size="2">pounds <input type="submit" value="Submit" /> </form></pre></body></html> _END; function sanitizeString($var) { $var = stripslashes($var); $var = htmlentities($var); $var = strip_tags($var); return $var; } ?> |