Current location: Hot Scripts Forums » Programming Languages » PHP » help radio buttons


help radio buttons

Reply
  #1 (permalink)  
Old 07-28-09, 03:02 AM
ajwatt ajwatt is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
help radio buttons

hi I have been playing around with this script for a few days now I am trying to get the radio buttons to set to the correct opton from the db. I have tried playing with if and else but no luck

HTML Code:
	<tr>
			<td align=\"right\">discounts:</td>
			
		<td>
			<input name=\"discount\" tabindex=\"1\" type=\"radio\" checked=\"checked\" value=\"full\"  >members:			
			<input name=\"discount\" tabindex=\"2\" type=\"radio\" value=\"half\" >Committee 50%
			<input name=\"discount\" tabindex=\"3\" type=\"radio\" value=\"free\" >Leader Free
			<input name=\"discount\" tabindex=\"4\" type=\"radio\" value=\"badge\" >Badge 20%
			
		</td>
PHP Code:

$discount=$_POST['discount']; 


help please

Last edited by wirehopper; 07-28-09 at 01:58 PM. Reason: Code tags
Reply With Quote
  #2 (permalink)  
Old 07-28-09, 01:59 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I would remove the backslashes from the input tags, unless there are in an echo statement.
Reply With Quote
  #3 (permalink)  
Old 07-28-09, 04:44 PM
ajwatt ajwatt is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
If I remove the backslashes I get this error

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/bhs49794/public_html/test12/admin/users.php on line 183

$discount is being read from a mysql db and needs to set the correct radio button

here is what I have tried but keep getting
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

PHP Code:




        $full 
"full";
        $

        
// lots of other code:

        
if ($discount $full) <td>
            <
input name=\"discount\" tabindex=\"1\" type=\"radio\" checked=\"checked\" value=\"$full\"  />members:    </td>
            else
            <td><input name=\"discount\" tabindex=\"1\" type=\"radio\" value=\"
$full\"  >members:
            }        
            <input name=\"discount\" tabindex=\"2\" type=\"radio\" checked=\"checked\" value=\"half price\" >Committee 50%
            <input name=\"discount\" tabindex=\"3\" type=\"radio\" value=\"free\" >Leader Free
            <input name=\"discount\" tabindex=\"4\" type=\"radio\" value=\"badge\" >Badge 20%</form> 

Last edited by wirehopper; 07-28-09 at 05:37 PM. Reason: PHP tags
Reply With Quote
  #4 (permalink)  
Old 07-28-09, 05:43 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Code:
if ($discount = $full) <td>
This will assign the value of full to discount, and the <td> tag after will probably cause an error.

Possible code:

PHP Code:

$aRadioButtons=array('badge'=>'Badge','free'=>'Free');

foreach (
$aRadioButtons as $k => $v)
{
  echo 
'<input type="radio" name="discount" value="'.$k.'"';
  if (
$discount==$k)
    echo 
'checked="checked"';
  echo 
' />';

Not tested.
Reply With Quote
  #5 (permalink)  
Old 07-28-09, 07:39 PM
ajwatt ajwatt is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
when I try that code each line that has " gives me this error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/bhs49794/public_html/test12/admin/users.php on line 199

line 199 echo '<input type="radio" name="discount" value="'.$k.'"';

if I change it to

echo '<input type=\"radio\" name=\"discount\" value=\"'.$k.'\"';

it works but this is displayed with the radio button

=array('badge'=>'Badge','free'=>'Free'); foreach ( as => ) { echo ''; }

same with

echo 'checked="checked"';

had to change to

echo 'checked=\"checked\"';

what am I missing here
thanks anthony
Reply With Quote
  #6 (permalink)  
Old 07-29-09, 04:12 AM
noorahmad noorahmad is offline
New Member
 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
?

this should help you:
Code:
<?PHP
$discount = 'full'; // Here is your discount getting $_POST
$dis = array('full'=>'memebers:','half'=>'Committee 50%','free'=>'Leader Free','badge'=>'Badge 20%');

echo "<form id='form1'>	";
	foreach($dis as $value=>$lable){
		echo "<input name='discount' type='radio' value='$value' ";
		if($value==$discount){
			echo 'checked ';
		}
		echo ">$lable:<br />";
	}
	echo "</form>";

?>

Last edited by noorahmad; 07-29-09 at 04:17 AM. Reason: ?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
reorder radio buttons tcloud Script Requests 3 09-22-08 08:04 AM
using java and radio buttons to choose search. PLEASE HELP!!! shelydmb JavaScript 1 03-13-06 03:19 PM
Accessing PHP array in HTML to make radio buttons Newbie2005 PHP 35 10-20-05 01:32 PM
radio buttons hugo84 ASP 1 08-02-05 02:04 AM
Help with radio buttons and uploading Arctic ASP 3 08-17-03 09:49 AM


All times are GMT -5. The time now is 07:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.