Pass Value of Radio Buttons through SQL Query

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:

<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

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

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

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

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; } ?>

Got teamviewer?

Dear Wilson382,

I do. What did you have in mind?

Chava

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

Dear Wilson382,

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

Sponsor our Newsletter | Privacy Policy | Terms of Service