# Pass Value of Radio Buttons through SQL Query

**URL:** <https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953>\
**Category:** MySQL database\
**Created:** [November 21, 2012, 12:08am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953 "2012-11-21T00:08:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chavad](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chavad](https://www.phphelp.com/u/chavad)\
**Post date:** [November 21, 2012, 12:08am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/1 "2012-11-21T00:08:04Z")

</div>

Dear Everyone,

I am very new to both PHP and MySQL. I have a MySQL database that includes a field called “max\_rooms” with the values 1 or 2 set for each row in the database it applies to. In my HTML document, I have a form containing a “Rooms?” question with two choices that are radio buttons. My PHP and MySQL are connected properly; I just don’t know what to write in the Results PHP document so that the values are passed correctly.

Here is the Rooms question in my form:

```auto
<div id="question" class="line_height_none">
            	<h2 class="heads">Rooms Needed?</h2>
                    <li class="no_liststyle">
                        <input type="radio" name="max_rooms" value="1" style="margin-right:10px; margin-bottom:10px;"/>One
                    </li>
                    
                    <li class="no_liststyle">
                        <input type="radio" name="max_rooms" value="2" style="margin-right:10px"/>Two
                    </li>
              </div> 
```

I don’t know if you need to see anything else.

Thank you so much!!!  
Chava

---

<div class="post-metadata">

**Author:** ![wilson382](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wilson382](https://www.phphelp.com/u/wilson382)\
**Post date:** [November 21, 2012, 12:11am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/2 "2012-11-21T00:11:43Z")

</div>

in your php script $\_POST[‘max\_rooms’] will contain the value of the selected radio.

from there you can run your insert or update query

---

<div class="post-metadata">

**Author:** ![chavad](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chavad](https://www.phphelp.com/u/chavad)\
**Post date:** [November 21, 2012, 12:34am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/3 "2012-11-21T00:34:25Z")

</div>

Dear wilson382,

Thanks so much for your help so far! I can understand the script you gave me, and I put that in; what do you mean by “from there you can run your insert or update query”? What else do I need in the PHP document?

Chava

---

<div class="post-metadata">

**Author:** ![wilson382](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wilson382](https://www.phphelp.com/u/wilson382)\
**Post date:** [November 21, 2012, 1:40am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/4 "2012-11-21T01:40:44Z")

</div>

hello,

Well you have MySQL Database, right?

Running queries is how to intaract with the database.

so first of all, you need to connect to the database

and then Insert your data to the database OR Update your data depending on your needs by running a query.

not sure what you want to accomplish i might be able to help if you show your codes

---

<div class="post-metadata">

**Author:** ![chavad](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chavad](https://www.phphelp.com/u/chavad)\
**Post date:** [November 21, 2012, 2:26am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/5 "2012-11-21T02:26:52Z")

</div>

Dear wilson382,

Below is basically my PHP code so far (I worked with someone and thought I could move on alone, but…); for the radio buttons, would I do something like this: (it didn’t work, but…)

$sqlquery = “SELECT \* FROM hallonly”;  
$sqlquery .=" where max\_rooms = $\_POST[‘max\_rooms’]";

Thanks so much!  
Chava

\<?php //connect to database $link = mysql\_connect('chavad.test.com', '\*\*\*\*\*\*\*', '\*\*\*\*\*\*'); if (!$link) {die('Could not connect: ' . mysql\_error());} //couple number validation DONT MOVE if (filter\_var($\_POST['couple\_number'],FILTER\_VALIDATE\_INT)) { $couples = $\_POST['couple\_number']; } else { $couples = 0; //default number if no number specified or they put in } $sqlquery = "SELECT \* FROM hallonly"; $sqlquery .= " where couple\_min \<= $couples and couple\_max \>= $couples"; //get the list of locations and put into sql query after surrounding with quotes foreach($\_POST['alocation'] as $x) { $locationlist.="'".$x."',"; } //information to display on search results mysql\_select\_db("wedding\_vendors"); $data = mysql\_query($sqlquery) or die(mysql\_error()); while($info = mysql\_fetch\_array( $data )) { $infotoprint ="
"; $infotoprint.="**".$info['address1']."  
".$info['address2'].""; $infotoprint .= "**"; Print $infotoprint; } ?\>

---

<div class="post-metadata">

**Author:** ![wilson382](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wilson382](https://www.phphelp.com/u/wilson382)\
**Post date:** [November 21, 2012, 2:30am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/6 "2012-11-21T02:30:06Z")

</div>

Got teamviewer?

---

<div class="post-metadata">

**Author:** ![chavad](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chavad](https://www.phphelp.com/u/chavad)\
**Post date:** [November 21, 2012, 2:42am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/7 "2012-11-21T02:42:34Z")

</div>

Dear Wilson382,

I do. What did you have in mind?

Chava

---

<div class="post-metadata">

**Author:** ![wilson382](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wilson382](https://www.phphelp.com/u/wilson382)\
**Post date:** [November 21, 2012, 4:02am UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/8 "2012-11-21T04:02:03Z")

</div>

I was thinking to help you with teamviewer since i’m not sure what you want to acomplish with your codes

send me your teamviewer ID and passcode on a personal message

---

<div class="post-metadata">

**Author:** ![chavad](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chavad](https://www.phphelp.com/u/chavad)\
**Post date:** [November 21, 2012, 3:04pm UTC](https://www.phphelp.com/t/pass-value-of-radio-buttons-through-sql-query/18953/9 "2012-11-21T15:04:52Z")

</div>

Dear Wilson382,

Thanks much; I finally figured it out this morning!  
Chava
