PHP - Help Me Resolve A Wierd Problem In A Form With Radio Buttons
Hello All,
I'm kinda new to PHP and web development and I seem to have a very wierd problem which is driving me nuts (for the last 2 days)...so I'd appreciate any and all help in getting it resolved.
Okay, so here's the problem:
In the code below, I used to have just the first statement below...which essentially accepted input as a textbox for a text field named qty_pkg (in the underlying MySQL table)...and that used to work just fine.
So then I decided to change the input type for that field to be a radio button, accepting one of two choices i.e. "UoM" or "Qty", and therefore I added the remainder of the code, whilst also commenting/remarking out the first statement.
What happens (when I added the radiobutton-related code) is that control no longer goes into the TRUE portion/logic of the "if ( !empty($_POST))" condition-check, but rather, it seems to go into the "ELSE/FALSE" portion of that conditional check. However, a record does get added to my table, even though I do not have an "INSERT INTO..." clause in the ELSE porition of that check. Also, what gets displayed on screen is as follows:
------------------------------------------------------------------------------------------------------------------------------------
Array()
There's something wrong somewhere!!!
Array()
------------------------------------------------------------------------------------------------------------------------------------
Now, if/when I comment/remark the radiobutton-related code, the "if ( !empty($_POST))" logic seems to work fine and the following is displayed on screen (which is what I expect):
------------------------------------------------------------------------------------------------------------------------------------
Array ( [datepicker] => 10/30/2014 [store_id] => 48 [new_store_name] => [item_id] => 5 [new_item_name] => [pkg_of] => 1 [price] => 1 [flyer_page] => 1 [limited_time_sale] => Array ( [0] => fri [1] => sat ) [nos_to_purchase] => 1 [create-and-add-more] => Create and Add More )
Notice: Undefined index: qty_pkg in /var/www/create.php on line 54 Array ( [0] => Array ( [item_id] => 5 [0] => 5 [item_name] => BD Cheese Strings [1] => BD Cheese Strings [section_id] => 7 [2] => 7 ) ) ------------------------------------------------------------------------------------------------------------------------------------ The other wierd thing is that if/when I now uncomment the first statement (which used to work just fine before) the "if ( !empty($_POST))" logic no longer seems to work the way it used to. Does/can someone see something wrong with my code somewhere? <!-- <?php echo standardInputField('Qty / Pkg', 'qty_pkg', $qty_pkg, $errors); ?> --> <div class="control-group"> <label class="control-label">Priced by:</label> <div class="priced-by-radio-container"> <div class="pb-radiobuttons-container"> <label class="indent-to-the-left"> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='UoM' $pb1> <span class='no-highlight'>Unit of Measure</span> </label> <label> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='Qty' $pb2> <span class='no-highlight'>Quantity</span> </label> </div> </div> </div> <?php echo standardInputField('UoM Name/Pkg. Of:', 'pkg_of', $pkg_of, $errors); ?> <?php echo standardInputField('Price:', 'price', $price, $errors); ?> <?php echo standardInputField('Flyer Page #:', 'flyer_page', $flyer_page, $errors); ?> print_r($_POST); if ( !empty($_POST)) { // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; ... ... $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); } else { echo "<br />There's something wrong somewhere!!!<br />"; print_r ($_POST); $qty_pkg = ''; $pkg_of = '';;Thanks. Similar TutorialsSo I have created an online test . I have the results from the form submitted to my email. It is working great but the only problem is that when a question is left unanswered, the radio button doesn't have a result. What i want it to do is when a question is left unanswered, the email should look like this (Question) 1_01: True 1_02: Unanswered 1_03: False 1_04: Unanswered 1_05: True Right now it looks like this: (Question) 1_01: True 1_03: False 1_05: True I can't make the radio button required because it is a timed test where you have to work fast, so unanswered questions are going to happen. How do I make it so that unanswered radio buttons submit the value "unanswered" in the E-mail? For some odd reason, when I add a snippet of PHP code to a certain page, it whitespaces the whole thing. I have other PHP snippets scattered around already. When I delete it, page is ok, with it, nothing but a grey border, all content is white. Freakin wierd. Here is the code... $day = date('d'); $month = date('m'); $year = date('Y'); $last = last_business_day($year,$month); $lastday = date('d', strtotime($last)); if($day > "15"){ $date2 = date("Y-m-" . $lastday); } else { $date2 = date("Y-m-15"); } $date1= date('Y-m-d'); $time = " 23:59:59"; $date3 = $date2 . $time; $agency = $_SESSION['AGENCY']; $agent = $_SESSION['AGENTNAME']; $query = "SELECT Amount1RS, SUM(BrokerFee), SUM(TotalCollected), SUM(Commission), AVG(BrokerFee), COUNT(ID) FROM accounting WHERE agency = '$agency' AND agent = '$agent' AND Amount1RS = 'New Business' AND Date BETWEEN '$newdate1' AND '$date3'"; $result = mysql_query($query); while($myrow = mysql_fetch_assoc($result)) {//begin of loop $totbroker = $myrow['SUM(BrokerFee)']; $avgbroker = $myrow['AVG(BrokerFee)']; $totcommission = $myrow['SUM(Commission)']; $totproduction = $myrow['SUM(Commission)'] + $myrow['SUM(BrokerFee)']; } $proquery = mysql_query("SELECT COUNT(ID) FROM clients WHERE Status = 'Prospect' AND Agency = '$agency' AND agentname = '$agent'") or die(mysql_error()); $prospects = mysql_fetch_array($proquery); $insquery = mysql_query("SELECT COUNT(ID) FROM clients WHERE Status = 'Insured' AND Agency = '$agency' AND agentname = '$agent'") or die(mysql_error()); $insureds = mysql_fetch_array($insquery); $closing = ($insureds / $prospects) * 100; $closing = floatval($closing); I even put it in teh <head> tag, same result. Anyone encountered this before? <?php session_start(); if (!$_SESSION["user_name"]) { // User not logged in, redirect to login page Header("Location: login.php"); } // Member only content // ... $con = mysql_connect('localhost','root',''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $result = mysql_query("select * from reference,users where reference.username=users.user_name AND reference.refid = '".$_POST['refid']."'"); while($row = mysql_fetch_array($result)) { echo $row['refid'];?><br><? echo $row['origin']; echo $row['dest']; echo $row['date']; echo $row['exdate']; echo $row['user_name']; } // ... // ... // Display Member information // echo "<p>User ID: " . $_SESSION["valid_id"]; //echo "<p>Username: " . $_SESSION["valid_user"]; //echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]); // Display logout link echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> for the above code i got error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in solve my problem Hi: I have few small issues with a Contact Us form I am putting together. 1 - When quotes or apostrophes are added to the input fields, they get turned into '\ (slashes). The "myCodeLib.php" file has a function to remove the slashes. I use it in the same way in the admin area and it works fine, so I don't see what I am missing: Code: [Select] <?php //STRIP SLASHES if(get_magic_quotes_gpc()) { $_POST = array_map('stripslashes',$_POST); $_GET = array_map('stripslashes',$_GET); $_COOKIE = array_map('stripslashes',$_COOKIE); } ?> 2 - A small issuse, but the Email validation doesn't seem to work entirely. It will accept a single character (like an "a") as valid, but it looks like it's suppose to check for a format like "a@a.com" 3 - How can I properly SPAN this code that write out the error: Code: [Select] echo $error; I want to do Code: [Select] <span class="textError">echo $error;</span> to make it red but I keep getting a snytax error This is the full code: Code: [Select] include('include/myConn.php'); include('include/myCodeLib.php'); <?php $error = NULL; $myDate = NULL; $FullName = NULL; $Address = NULL; $City = NULL; $State = NULL; $Zip = NULL; $Phone = NULL; $Email = NULL; $Website = NULL; $Comments = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $FullName = $_POST['FullName']; $Address = $_POST['Address']; $City = $_POST['City']; $State = $_POST['State']; $Zip = $_POST['Zip']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Website = $_POST['Website']; $Comments = $_POST['Comments']; if(empty($FullName)) { $error .= '-- Enter your Full Name. <br />'; } if(empty($Email) || preg_match('~^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$~',$Email)) { //<- if email is empty, or doesn't follow the expression. $error .= '-- Enter your Email. <br />'; //<- this is the error message. } if($error == NULL) { $sql = sprintf("INSERT INTO myContactData(myDate,FullName,Address,City,State,Zip,Phone,Email,Website,Comments) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')", //<-database structure must be right. mysql_real_escape_string($myDate), mysql_real_escape_string($FullName), mysql_real_escape_string($Address), mysql_real_escape_string($City), mysql_real_escape_string($State), mysql_real_escape_string($Zip), mysql_real_escape_string($Phone), mysql_real_escape_string($Email), mysql_real_escape_string($Website), mysql_real_escape_string($Comments)); if(mysql_query($sql)) { $error .= 'Thank you for your comment!'; } else { $error .= 'There was an error in our Database, please Try again!'; } } } echo $error; $myDate = $_REQUEST['myDate'] ; $FullName = $_REQUEST['FullName'] ; $Address = $_REQUEST['Address'] ; $City = $_REQUEST['City'] ; $State = $_REQUEST['State'] ; $Zip = $_REQUEST['Zip'] ; $Phone = $_REQUEST['Phone'] ; $Email = $_REQUEST['Email'] ; $Website = $_REQUEST['Website'] ; $Comments = $_REQUEST['Comments'] ; mail( "email@website.com", "Contact Request", "Date Sent: $myDate\nFull Name: $FullName\nAddress: $Address\n City: $City\n State: $State\n Zip: $Zip\n Phone: $Phone\n Email: $Email\n Website: $Website\n Comments: $Comments\n", "From: $Email" ); ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> <div id="tableFormDiv"> <fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">* - Required</span></span> <span class="floatFormLeft"> </span></fieldset> <fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">*</span> Full Name:</span> <span class="floatFormLeft"><input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">Address:</span> <span class="floatFormLeft"><input type="text" name="Address" size="45" maxlength="50" value="<?php echo $Address; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">City:</span> <span class="floatFormLeft"><input type="text" name="City" size="45" maxlength="50" value="<?php echo $City; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">State:</span> <span class="floatFormLeft"><input type="text" name="State" size="45" maxlength="50" value="<?php echo $State; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">Zip:</span> <span class="floatFormLeft"><input type="text" name="Zip" size="45" maxlength="50" value="<?php echo $Zip; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">Phone:</span> <span class="floatFormLeft"><input type="text" name="Phone" size="45" maxlength="50" value="<?php echo $Phone; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth"><span class="textErrorItalic">*</span> Email:</span> <span class="floatFormLeft"><input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">Website:</span> <span class="floatFormLeft"><input type="text" name="Website" size="45" maxlength="50" value="<?php echo $Website; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth">Comments:</span> <span class="floatFormLeft"><textarea name="Comments" cols="40" rows="10"><?php echo $Comments; ?></textarea></span></fieldset> </div> <input type="submit" name="submit" value="Submit" class="submitButton" /><br /> </form> </div> Can someone please help me with this... now i am getting this error ( ! ) Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'talos342c'@'localhost' (using password: YES) in C:\wamp\www\myNewweb\storescripts\connect_to_mysql.php on line 19 Call Stack # Time Memory Function Location 1 0.0008 380440 {main}( ) ..\index.php:0 2 0.0012 384880 include( 'C:\wamp\www\myNewweb\storescripts\connect_to_mysql.php' ) ..\index.php:11 3 0.0012 385528 mysql_connect ( ) ..\connect_to_mysql.php:19 Hello guys. I am learning PHP little by little and am writing a VERY basic quiz. For functionality in the future I want to be able to change questions and answers in one "included" php doc. The problem i am having with my current code is that I would like to place a variable in the "value" definition on the radio input. I am unable to do this I guess. Any suggestions to accomplish the same thing? Sorry for my horrible code, this is the first thing I have written from scratch. The form page: Code: [Select] <?php include ("test.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <h2><? print $q1; ?></h2> <form method="post" action="test.php"> <input type="radio" name="q1answered" value="Basketball"/> <?php print $q1ans[0]; ?> <input type="radio" name="q1answered" value="Football"/> <?php print $q1ans[1]; ?> <br /><br /> <input type="submit" value="Submit Your Answer!" name="submit" /> </form> </body> </html> The php Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php //Enter all questions below $q1 = "What is your favorite Sport?"; $q2 = "What is your favorite hobby?"; //End Questions //Enter Asnwer choices for each question $q1ans = array("Basketball", "Football"); //End Answers //All question defined variables here to make grading easier $qbank = array ($q1, $q2,); if (isset($_POST["submit"])) { $choice = $_POST["q1answered"]; if ($choice == $q1ans[0]){ print "Your Favorite Sport is $q1ans[0]."; } else { print "Your Favorite Sport is $q1ans[1]."; } } ?> </body> </html> Thanks! I'm totally naive to php coding and i'm trying to modify my website which was written for me by someone else in php. So i'm kind of shooting in the dark - but my modification really isn't that difficult... here goes. I already have a form set up allowing the user to select values from drop down menus. To this I want to add a further selection from a choice of 4 radio buttons. This is the coding I've used (i've stripped it down to basics for simplicity) it's inserted between the 'form' tags <input type=radio name="choice" value="FP"> Front Print<br> <input type=radio name="choice" value="BP"> Back Print<br> <input type=radio name="choice" value="PP"> Pocket Print<br> <input type=radio name="choice" value="CP"> Custom Print<br> Ok - this part displays ok and seems to function as expected. The form 'Action' sends the user to another php page so i need to access these values on a different page. This is where I'm running blind. I just want a simple 'if' statement to set a variable based on the value of the radio buttons. So something that looks like this.... if (choice[1].checked=true) {$printchoice = "Front Print";} if (choice[2].checked=true) {$printchoice = "Back Print";} if (choice[3].checked=true) {$printchoice = "Pocket Print";} if (choice[4].checked=true) {$printchoice = "Custom Print";} This part doesn't work - i've tried various combinations but i'm just taking wild guesses. Any help would be much appreciated - thanks Code: [Select] if ($cartype = 1 ) { echo "Compact <br/>"; } elseif ($cartype == 2 ) { echo "Saloon <br/>"; } else if ($cartype == 3 ) { echo "SUV <br/>"; } This code will only display the first radio button atm. How do I fix this? I have made a form which includes text fields and radio buttons. The user completes the fields and makes their selections. Once the form is submit, they are then directed to a php file which displays their entries and selections. Atm I can't quite work out how to post their radio button selections. Here is the form: <legend>Car type</legend> <input name="cartype" type="radio" value="1" id="carone" /> <label for="carone">Compact</label><br /> <input name="cartype" type="radio" value="2" id="cartwo" /> <label for="cartwo">Saloon</label><br /> <input name="cartype" type="radio" value="3" id="carthree" /> <label for="carthree">SUV</label> and here is my current code for the text fields: <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $emailaddress = $_POST['emailaddress']; $phone = $_POST['phone']; echo "Dear ". $firstname . " " . $lastname . ",<br />"; echo "Thank you for your order. <br />"; echo "Your contact details a - <br />"; echo "phone: " . $phone . "<br />"; echo "email: " . $emailaddress . "<br />"; ?> </body></html> If anyone could give a hand I'd be very grateful! I'm not sure how to use foreach to send multiple form information to the database. <form> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="1" checked="checked" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="2" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="3" /> </form> I have a group of 3 buttons for three different options and this is in a php while loop,and there could be anywhere from 1 to 30 of these forms that ineed to send the data to the database at the same time. each one of these groups are next to a user to mark if they were present, tardy, or absent. I need it to get the id of the user for each one of these and send the value to the database as well. I have been at this for far too long and really need some help. I am just trying to check if a radio button has been set or not when someone hits submit. My validation looks something like this: function protect($string){ $string = trim(strip_tags(addslashes($string))); return $string; } if(isset($_POST['submit'])){ //protect and then add the posted data to variables $username = protect($_POST['username']); $password = protect($_POST['password']); $passconf = protect($_POST['passconf']); $email = protect($_POST['email']); $fname = protect($_POST['fname']); $lname = protect($_POST['lname']); $address = protect($_POST['address']); $phone = protect($_POST['phone']); $gender = $_POST['gender']; if(!$username || !$password || !$passconf || !$email || !$fname || !$lname || !$address || !$phone || !isset($gender)){ echo "<p>Please enter all required fields</p>"; }else{ and my form for the radio button is like this... <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h1>General</h1> <p> <label for="username">Username: </label> <input type="text" name="username" value="<?=$_POST['username'] ?>" /> </p> <p> <label for="password">Password: </label> <input type="password" name="password" value="<?=$_POST['password'] ?>" /> </p> <p> <label for="passconf">Confirm Password: </label> <input type="password" name="passconf" value="<?=$_POST['passconf'] ?>" /> </p> <p> <label for="email">Email: </label> <input type="text" name="email" value="<?=$_POST['email'] ?>" size="25"/> </p> <p> <label for="fname">First Name: </label> <input type="text" name="fname" value="<?=$_POST['fname'] ?>" size="25"/> </p> <p> <label for="lname">Last Name: </label> <input type="text" name="lname" value="<?=$_POST['lname'] ?>" size="25"/> </p> <p> <label for="address">Home Address: </label> <input type="text" name="address" value="<?=$_POST['address'] ?>" /> </p> <p> <label for="phone">Primary Phone Number: </label> <input type="text" name="phone" value="<?=$_POST['phone'] ?>" size="10" /> </p> <p> <label for="genders">Gender: </label> <input type="radio" name"gender" value="male" /> Male <input type="radio" name"gender" value="female" /> Female </p> everytime i hit submit i get this error: "Notice: Undefined index: gender in C:\wamp\www\LoginRegistration\register.php on line 37 Please enter all required fields" can anyone help me please? Hi guys...I need some help in matching data from results of checkboxs and radio buttons. My Intentions: There are 3 radio buttons and 8 check boxes. Users can select any one but cannot don't select at all. I separate the calss and categories because for classes, users can only select 1 option whereas for categories users can select many. For example, User select class 1 but do not select anything else and click submit...the system will then retrieve that he selected and check the data base if he have the pre requisites to allow him to go through. Coding for my form: Code: [Select] <form id="applicationoptions" method="post" action="s_apply_now.php"> <div id="optionshead">Class :</div> <div id="classoptions"> <input type="radio" name="class" value="1" /> Class 1 Permit <input type="radio" name="class" value="2" /> Class 2 Permit <input type="radio" name="class" value="3" /> Class 3 Permit </div> <div id="optionshead2">Categories :</div> <div id="catoptions"> <input type="checkbox" name="cat" value="1" /> CAT 2PG <input type="checkbox" name="cat" value="2" /> CAT 1OR <input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/> <input type="checkbox" name="cat" value="4" /> CAT 3PG <input type="checkbox" name="cat" value="5" /> CAT 2OR <input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/> <input type="checkbox" name="cat" value="7" /> CAT 4PG <input type="checkbox" name="cat" value="8" /> CAT 3OR </div> <div class="applynext"> <input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" /> </div> </form> Lets say if user do not select any class, but select CAT 3PG, system will check if user have the pre-requisites before proceeding to next step. Any one can help me or give me hints?? most importantly is i do not know how to retreieve the values selected from the form. Is it possible to do it using php or must i hunt for javascript's script?? Thanks in advance guys...greatly appreciate. Hi, I have the below code which pulls pet types from the database, and when you pick the particular type by selecting a radio button amd press 'Select Pet Type' you are brought to a page listing all examples of that pet. Is there any way of changing this so the pet types are listed as hyperlinks instead and when you click each particular hyperlink you are brought to a page where that pet type is listed? <?php /* Program: PetCatalog.php * Desc: Displays a list of pet categories from the PetType table. Includes descriptions. * Displays radio buttons for user to check. */ ?> <html> <head><title>Pet Types</title></head> <body> <?php include("misc.inc"); #12 $cxn = mysqli_connect($host,$user,$password,$dbname) #14 or die ("couldn't connect to server"); /* Select all categories from PetType table */ $query = "SELECT * FROM pettype ORDER BY petType"; #18 $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); #20 /* Display text before form */ echo "<div style='margin-left: .1in'>\n <h1 style='text-align: center'>Pet Catalog</h1>\n <h2 style='text-align: center'>The following animal friends are waiting for you.</h2>\n <p style='text-align: center'>Find just what you want and hurry in to the store to pick up your new friend.</p> <h3>Which pet are you interested in?</h3>\n"; /* Create form containing selection list */ echo "<form action='ShowPets.php' method='POST'>\n"; #33 echo "<table cellpadding='5' border='1'>"; $counter=1; #35 while($row = mysqli_fetch_assoc($result)) #36 { extract($row); #38 echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n"; echo "<input type='radio' name='interest' value='$petType'\n"; #43 if( $counter == 1 ) #44 { echo "checked"; } echo ">$petType</td>"; #48 echo "<td>$typeDescription</td></tr>"; #49 $counter++; #50 } echo "</table>"; echo "<p><input type='submit' value='Select Pet Type'> </form></p>\n"; #54 ?> </div> </body></html> Hi community. The radio buttons on my form suddenly stopped working. For the life of me I can’t figure out why. Everything seems to look fine. I did some moving around on servers so I wonder if something got messed up during the transfer. I’m wondering if a new version of PHP was installed and made something obsolete. I was wondering if someone could take a look. Thank you in advance for your advise.
<form action="brian_1.php" method="post" name="form1" id="form1"> <input name="name" type="text" id="name" size="30" tabindex="1"/> Company if Applicable: <input name="company" type="text" id="company" size="30" tabindex="2"/> Phone: <input name="phone" type="text" id="phone" tabindex="3" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="12"/> Example: XXXXXXXXXX Alternate Phone: <input name="altphone" type="text" id="altphone" tabindex="4" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="13"/> Example: XXXXXXXXXX Street Address:<input name="mail" type="text" id="mail" size="60" tabindex="5"/> City, State, Zip Code: <input name="city" type="text" id="city" size="60" tabindex="5"/> E-mail: <input name="emai" type="text" id="emai" size="60" tabindex="6"/> Would you like to be part of our mailing list? <label><input type="radio" name="list" value="Yes" id="RadioGroup1_0" tabindex="7"/>Yes</label><label><input type="radio" name="list" value="No" id="RadioGroup1_1" tabindex="8"/>No</label> Are you interested in volunteering for upcoming events? <label><input type="radio" name="volunteer" value="Yes" id="RadioGroup2_0" tabindex="9"/>Yes</label><label><input type="radio" name="volunteer" value="No" id="RadioGroup2_1" tabindex="10"/>No</label> Are you interested in becoming a sponsor by receiving opportunities to advertise through us? <label><input type="radio" name="opportunities" value="Yes" id="RadioGroup3_0" tabindex="11"/>Yes</label><label><input type="radio" name="opportunities" value="No" id="RadioGroup3_1" tabindex="12"/>No</label> Would you like to join our efforts by offering your services or products to further our cause? <label><input type="radio" name="cause" value="Yes" id="RadioGroup4_0" tabindex="15"/>Yes</label><label><input type="radio" name="cause" value="No" id="RadioGroup4_1" tabindex="16"/>No</label> If so, in what ways would you like to contribute? <textarea name="contribute" cols="60" rows="4"></textarea> <input type="submit" name="Submit" value="Sumbit" /><input type="reset" name="reset" id="reset" value="Clear" /> </form> <?php /* Email Variables */ $emailSubject = 'Contact Form'; $webMaster = 'brianewagnerfund@gmail.com'; $webMaster = 'matt@webskillsplus.com'; //$webMaster = 'murrterr@rcn.com'; /* Data Variables */ $name = $_POST['name']; $company = $_POST['company']; $phone = $_POST['phone']; $altphone = $_POST['altphone']; $mail = $_POST['mail']; $city = $_POST['city']; $emai = $_POST['emai']; if (isset($_POST["submit"])) { echo $_POST["list"]; } if (isset($_POST["submit"])) { echo $_POST["volunteer"]; } if (isset($_POST["submit"])) { echo $_POST["opportunities"]; } if (isset($_POST["submit"])) { echo $_POST["cause"]; } $contribute = $_POST['contribute']; $body = <<<EOD \r\n \r\n <br> Name(s): $name \r\n <br> Company if Applicable: $company \r\n <br> Phone: $phone \r\n <br> Alternate Phone: $altphone \r\n <br> Street Address: $mail \r\n <br> City, State, Zip Code: $city \r\n <br> Email: $emai \r\n <br> Would you like to be part of our mailing list? $list \r\n <br> Are you interested in volunteering for upcoming events? $volunteer \r\n <br> Are you interested in becoming a sponsor by receiving opportunities to advertise through us? $opportunities \r\n <br> Would you like to join our efforts by offering your services or products to further our cause? $cause \r\n <br> If so, in what ways would you like to contribute? $contribute \r\n <br> EOD; $from = "From: BrianEWagnerFund@gmail.com\r\n"; $from .= "Reply-To: ".$emai."\r\n"; $from .= "Content-type: text/html\r\n"; mail($webMaster, $emailSubject, $body, $from); /* Results rendered as HTML */ echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.brianewagnerfund.org/thankyou.html\">"; ?> I have been searching for something like this to use so I am trying to implement these ideas for my form but unable to get it to work. The concept is similar so I am posting here but if I would make a new post just let me know. it is not posting the info when the radio button is checked. Someone with a keener eye that mine can give a look and tell what I have done incorrectly it would be appreciated. Code: [Select] echo ' <form action="" method="get"><div id="avatar_section"> <div id="avatar_stack"> <p> <img src="herotmb/face0.png" alt="" /><input name="avatar[head]" type="radio" value="face0" checked="checked" /> </p> <p> <img src="herotmb/face0.png" alt="" /><input type="radio" name="avatar[face]" value="face0" /> <img src="herotmb/face1.png" alt="" /><input type="radio" name="avatar[face]" value="face1" /> <img src="herotmb/face2.png" alt="" /><input type="radio" name="avatar[face]" value="face2" /> <img src="herotmb/face3.png" alt="" /><input type="radio" name="avatar[face]" value="face3" /> </p> <span name="color"> <p> <img src="herotmb/color0.png" alt="" /><input type="radio" name="avatar[color]" value="black" id="black" onclick="color(black);" /> <img src="herotmb/color1.png" alt="" /><input type="radio" name="avatar[color]" value="brown" id="brown" /> <img src="herotmb/color2.png" alt="" /><input type="radio" name="avatar[color]" value="darkbrown" id="darkbrown" onclick="color(darkbrown);" /> <img src="herotmb/color3.png" alt="" /><input type="radio" name="avatar[color]" value="yellow" id="red" onclick="color(red);" /> <img src="herotmb/color4.png" alt="" /><input type="radio" name="avatar[color]" value="red" id="yellow" onclick="color(yellow);" /> </p> </span> '; $selected_radio = '$_POST[avatar[color]]'; if ($selected_radio == 'black') { echo ' <p> <img src="herotmb/hair0-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-black" /> <img src="herotmb/hair5-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair5-black" /> <img src="herotmb/hair6-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair6-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'brown') { echo 'Table 2 Here.'; } else if ($selected_radio == 'darkbrown') { echo 'Table 3 Here.'; } else if ($selected_radio == 'red') { echo 'Table 4 Here.'; } else if ($selected_radio == 'yellow') { echo 'Table 5 Here.'; } echo ' <p id="submit" > <input type="submit" value="Save" /> </p> </form>'; Sorry if this should be in the HTML forum but as it is relating to something I am trying to do with php I thought this was the right place! I am creating a search page and one of the columns has only two potential values, 'H' for Home Games and 'A' for Away Games. Using radio buttons I can get the search page to filter correctly but there will also be times, once there are a few more search options on there, when a search would want to show All Games. The current form I have is Code: [Select] <form id="form1" name="form1" method="post" action="fixrestestsearch.php"> <p> <label for="OPP">OPP</label> <input type="text" name="OPP" id="OPP" /> <br /> <label> <input type="radio" name="HA" value="H" id="HA_0" /> Home</label> <br /> <label> <input type="radio" name="HA" value="A" id="HA_1" /> Away</label> <br /> <label> <input type="radio" name="HA" value="" id="HA_2" /> All</label> <br /> <br /> SUB <input type="submit" name="SUB" id="SUB" value="Submit" /> </p> </form> and the query in the results page contains Code: [Select] WHERE team_name='$OPP' AND h_a='$HA' If either the 'Home' or 'Away' buttons are checked everything works fine. If I check the 'All' button nothing is returned as it is looking for blank cells. I have also tried using 'value="*"' but that did not work. Is there anything that I can put as the value of a radio button that would select all records or would it have to be something amended in the query on the results page? Thanks in advance Steve In this form, I am using radio buttons to select various PHP math function results (total, average,both) and it works but was wondering if it is possible to make it multiple choice, that is to say instead of displaying one result at t time when you submit, displaying two or three of the results, depending on how many radio buttons are clicked. Can this be done? Here is the form code <form action="." method="post"> <input type="hidden" name="action" value="process_scores" /> <label>Score 1:</label> <input type="text" name="scores[]" value="<?php echo $scores[0]; ?>"/><br /> <label>Score 2:</label> <input type="text" name="scores[]" value="<?php echo $scores[1]; ?>"/><br /> <label>Score 3:</label> <input type="text" name="scores[]" value="<?php echo $scores[2]; ?>"/><br /> <!-- ADD LOGIC TO DETERMINE WHETHER TO CALCULATE AVERAGE, TOTAL OR BOTH --> <fieldset> <legend> What do you want to calculate?</legend> <p> <input type="radio" name="calculate" value="average" checked="checked" /> Average<br /> <input type="radio" name="calculate" value="total" />Total<br /> <input type="radio" name="calculate" value="both" />Both</p> <p><br /> </p> </fieldset> <br /><br /> <label> </label> <input type="submit" value="Process Scores" /><br /> <label>Scores:</label> <span><?php if (isset($scores_string)) { echo $scores_string; } ?></span><br /> <label>Score Total:</label> <span><?php if (isset($score_total)) { echo $score_total; } ?></span><br /> <label>Average Sco </label> <span><?php if (isset($score_average)) { echo $score_average; } ?></span><br /> </form> and the processing code <?php if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = 'start_app'; } if (isset($_POST['calculate'])) { $calculate = $_POST['calculate']; } switch ($action) { case 'start_app': $scores = array(); $scores[0] = 70; $scores[1] = 80; $scores[2] = 90; break; case 'process_scores': $scores = $_POST['scores']; // validate the scores $is_valid = true; for ($i = 0; $i < count($scores); $i++) { if (empty($scores[$i]) || !is_numeric($scores[$i])) { $scores_string = 'You must enter three valid numbers for scores.'; $is_valid = false; break; } } if (!$is_valid) { break; } // process the scores $scores_string = ''; $score_total = 0; foreach ($scores as $s) { $scores_string .= $s . '|'; $score_total += $s; } $scores_string = substr($scores_string, 0, strlen($scores_string)-1); // calculate the average $score_average = $score_total / count($scores); // format the total and average switch($calculate) { case 'average': $score_average = number_format($score_average, 2); $score_total = ""; break; case 'total': $score_average = ""; $score_total = number_format($score_total, 2); break; case 'both': $score_total = number_format($score_total, 2); $score_average = number_format($score_average, 2); break; } break; } include 'loop_tester.php'; ?> Hi, I need to analyze a string and get the text between, before, and after the forward slashes.. The string will always look something like this, but will vary: $str = "I will go to the store with <# one/two/three #> people." Then I need to create a form with radio buttons for each choice. In this case (one, two, or three). The text between the <# ... #> could be different every time, and with uknown amount of forward slashes. Here is what I have so far but it doesn't work. Code to find if there are slashes: Code: [Select] preg_match_all( '/([/]+)/',$str,$matches); Code to create html form .. Code: [Select] $i = 0; $html = '<form>'; foreach ($matches[0] as $match){ if ($pos = strpos( $str,$match ) ) === false ) continue; } $html .= '<input type="radio" name="place-' . $i . '" value=". $match . '" /> '; } $html .= '</form>'; Its not working as needed. I'm not sure how to create radio button choices for the words (one, two, three). Thanks I have a table that shows all the users in my table. Each user is either a user or an admin. I have radio buttons for each user determining if they are a user or an admin Right now I have each RB group named userlevel0, userlevel1, userlevel2 etc.. How can I get all the groups dynamically? I attempted an html array but failed. |