need help in PHP

Hi,

I am using a html form which has text boxes and radio buttons. The content in the text boxes are mandatory, but the user wont need to select all radio buttons. He can select any one or two radio buttons in the list of ten topics.

Can you help me out how to pull the value only from the selected radio buttons through PHP? I need all the selected values to be mailed to my mail-id?

[php]

<?php $to = "[email protected]"; $from = $_REQUEST['ename']; $subject = "PHP Test Mail"; $message = $_REQUEST['radiobuttonname']; [/php] //how to pull the data from the selected radio button in the form? Kindly help

In your form code it should have

If something2 is POST then change all the $_REQUEST to $_POST

@RaythXC: It works…Thanks for your help…

@RaythXC: Is this a correct way?

[php]
$message = $_POST[‘habitsbeginners’] . $_POST[‘feedback’] . $_POST[‘executive’] . $_POST[‘acing’];
[/php]

I have selected habitsbeginners, executive & acing buttons. it showing a error message after submitting the form:

Notice: Undefined index: feedback in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\odrequest.php on line 13

Please help

Hi there,

The undefined index error means that there is no value for the array $_POST[‘feedback’] or another array that you have that contains the “[‘feedback’]” in it. If it is from the $_POST array, you need to make sure that there is a field named feedback in your form and that it’s spelled just like the index in the $_POST array. You need to check your form as well as this script and make sure they are the same and you should be golden.

Hope this helps.

See the HTML code below:

<form name="odform" action="odrequest.php" method="POST">
<input type="radio" name="habitsbeginners" value="7hab">
<input type="radio" name="feedback" value="feed">
<input type="radio" name="executive" value="exec">
<input type="radio" name="acing" value="ace">

The user can select any one or more radio buttons, and I want to pass the data to PHP…I dont know how to do that.

and here goes the PHP code:
[php]

<?php $to = "[email protected]"; $from = $_POST['ename']; $subject = "PHP Test Mail"; $message = $_POST['habitsbeginners'] . $_POST['feedback'] . $_POST['executive'] . $_POST['acing']; mail($to, $subject, "Hi, " . $message, "From:" . $from); [/php] Is this correct format?

You have to validate the post data. The way it is now, it will try to retrieve the form data even if the radio button isn’t checked or not.

Sponsor our Newsletter | Privacy Policy | Terms of Service