473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP, Dropdowns, and Radio buttons

anyone can help me in form handling - dropdown list and radio button. i want the php code to handle this dropdown list and radio button.
May 8 '07 #1
6 1850
pbmods
5,821 Expert 4TB
i want the php code to handle this dropdown list and radio button.
Don't we all.

How far have you gotten? Are you getting errors? Is your script not working the way it's supposed to?
May 8 '07 #2
devsusen
136 100+
Don't we all.
well said pbmods. I am agreed with u. :)

susen
May 8 '07 #3
i need a simple php code storing dropdown list and radiobutton data into my mysql database.
May 9 '07 #4
pbmods
5,821 Expert 4TB
i need a simple php code storing dropdown list and radiobutton data into my mysql database.
So you haven't written it yet is what you're saying. Ok then.

Well, the basics are pretty simple. Each item in your form should have a name:

[HTML]
<input name="flavor" ...
[/HTML]

When the User submits the form, PHP puts the value of that input into $_REQUEST (also $_GET, $_POST or one of a couple others, depending on the action of your form). So to access that value, you would type something like this:

[PHP]
echo $_REQUEST['flavor'];
[/PHP]

To save it to the database, you'd need to build a query and send it:
[PHP]
$query = "INSERT INTO `tableName` (`col1`, `col2`) VALUES('" . addslashes($_REQUEST['flavor']) . "', '" . addslashes($_REQUEST['caliber']) . "')";
[/PHP]

And so forth. Note that it is good practice to (at the very least) use addslashes to prevent SQL injection attacks.
May 9 '07 #5
actually i'm new to php, so i don't understand the code. this is my html code, so i hope that anyone can help me...

<input type="radio" name="formradio1" style="position:absolute;left:299px;top:725px;z-index:10">
<input type="radio" name="formradio1" style="position:absolute;left:300px;top:799px;z-index:11">
<input type="radio" name="formradio1" style="position:absolute;left:300px;top:616px;z-index:12">
<input type="radio" name="formradio1" style="position:absolute;left:300px;top:653px;z-index:13">
<input type="radio" name="formradio1" style="position:absolute;left:300px;top:761px;z-index:14">
<input type="radio" name="formradio1" style="position:absolute;left:300px;top:688px;z-index:15">
<input name="formtext1" type="text" style="position:absolute;width:335px;left:326px;to p:818px;z-index:16">
<select name="Ruangan" style="position:absolute;left:325px;top:440px;widt h:336px;z-index:17">
<option value="">Bilik Komputer Sains Fizik</option>
</select>

<select name="Hingga" style="position:absolute;left:325px;top:584px;widt h:118px;z-index:18">
<option value="">9.00</option>
<option value="">10.00</option>
<option value="">11.00</option>
<option value="">12.00</option>
<option value="">1.00</option>
<option value="">2.00</option>
<option value="">3.00</option>
<option value="">4.00</option>
<option value="">5.00</option>
<option value="">6.00</option>
<option value="">7.00</option>
<option value="">8.00</option>
<option value="">9.00</option>
<option value="">10.00</option>
</select>

<select name="formselect3" style="position:absolute;left:325px;top:476px;widt h:168px;z-index:19">
<option value="">Isnin</option>
<option value="">Selasa</option>
<option value="">Rabu</option>
<option value="">Khamis</option>
<option value="">Jumaat</option>
<option value="">Sabtu</option>
<option value="">Ahad</option>
</select>

<select name="Dari" style="position:absolute;left:325px;top:549px;widt h:118px;z-index:20">
<option value="">8.00</option>
<option value="">9.00</option>
<option value="">10.00</option>
<option value="">11.00</option>
<option value="">12.00</option>
<option value="">1.00</option>
<option value="">2.00</option>
<option value="">3.00</option>
<option value="">4.00</option>
<option value="">5.00</option>
<option value="">6.00</option>
<option value="">7.00</option>
<option value="">8.00</option>
</select>

<div id="text4" style="position:absolute; overflow:hidden; left:108px; top:98px; width:522px; height:28px; z-index:21"><div class="wpmd">
<div align=justify><font color="#253B6D">Sila pilih kategori </font><font color="#253B6D"><B>TEMPAHAN RUANG</B></font><font color="#253B6D">.</font></div>
<div align=justify><font color="#253B6D"> </font></div>
</div></div>

<div id="nav2" style="position:absolute; left:132px; top:131px; z-index:22"><a onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('nav20','','images/nav55583920a.gif',1)" href="TempahMakmal.html"><img name="nav20" onLoad="MM_preloadImages('images/nav55583920a.gif')" alt="" border=0 src="images/nav55583920i.gif"></a></div>
<div id="nav2" style="position:absolute; left:132px; top:171px; z-index:22"><a onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('nav21','','images/nav55583921a.gif',1)" href="TempahSeminar.html"><img name="nav21" onLoad="MM_preloadImages('images/nav55583921a.gif')" alt="" border=0 src="images/nav55583921i.gif"></a></div>
<div id="nav2" style="position:absolute; left:132px; top:211px; z-index:22"><a onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('nav22','','images/nav55583922a.gif',1)" href="TempahMesyuarat.html"><img name="nav22" onLoad="MM_preloadImages('images/nav55583922a.gif')" alt="" border=0 src="images/nav55583922i.gif"></a></div>
<div id="nav2" style="position:absolute; left:132px; top:251px; z-index:22"><a onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('nav23','','images/nav55583923a.gif',1)" href="TempahPeperiksaan.html"><img name="nav23" onLoad="MM_preloadImages('images/nav55583923a.gif')" alt="" border=0 src="images/nav55583923i.gif"></a></div>

<select name="hari" style="position:absolute;left:358px;top:512px;widt h:49px;z-index:23">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
<option value="">6</option>
<option value="">7</option>
<option value="">8</option>
<option value="">9</option>
<option value="">10</option>
<option value="">11</option>
<option value="">12</option>
<option value="">13</option>
<option value="">14</option>
<option value="">15</option>
<option value="">16</option>
<option value="">17</option>
<option value="">18</option>
<option value="">19</option>
<option value="">20</option>
<option value="">21</option>
<option value="">22</option>
<option value="">23</option>
<option value="">24</option>
<option value="">25</option>
<option value="">26</option>
<option value="">27</option>
<option value="">28</option>
<option value="">29</option>
<option value="">30</option>
<option value="">31</option>
</select>

<select name="Bulan" style="position:absolute;left:462px;top:512px;widt h:79px;z-index:24">
<option value="">Jan</option>
<option value="">Feb</option>
<option value="">Mac</option>
<option value="">April</option>
<option value="">Mei</option>
<option value="">Jun</option>
<option value="">Julai</option>
<option value="">Ogos</option>
<option value="">September</option>
<option value="">Oktober</option>
<option value="">November</option>
<option value="">Disember</option>
</select>

<select name="Tahun" style="position:absolute;left:603px;top:512px;widt h:59px;z-index:25">
<option value="">2007</option>
<option value="">2008</option>
<option value="">2009</option>
<option value="">2010</option>
<option value="">2011</option>
<option value="">2012</option>
<option value="">2013</option>
<option value="">2014</option>
<option value="">2015</option>
<option value="">2016</option>
<option value="">2017</option>
<option value="">2018</option>
<option value="">2019</option>
<option value="">2020</option>
</select>

<select name="AMPM" style="position:absolute;left:452px;top:583px;widt h:56px;z-index:26">
<option value="">AM</option>
<option value="">PM</option>
</select>

<select name="AMPM" style="position:absolute;left:450px;top:548px;widt h:56px;z-index:27">
<option value="">AM</option>
<option value="">PM</option>
</select>

<input name="formtext2" type="text" style="position:absolute;width:336px;left:325px;to p:402px;z-index:28">
<input name="formbutton1" type="submit" value="HANTAR" style="position:absolute;left:587px;top:881px;z-index:29">

</div></body>
</html>
May 10 '07 #6
I don't mean to sound patronising, but I think what you really need to do is get a book on PHP and read up on the basics before getting gong. I recommend Larry Ullman's php books. That's how I got started.

Before you do any php stuff your html form needs sorting out:
Each radio button needs a value, e.g.
Please choose your favorite food:<br>
[HTML]<input type="radio" name="choose_food" value="cheese">Cheese<br>
<input type="radio" name="choose_food" value="carrots">Carrots<br>
Please choose your gender:<br>
<input type="radio" name="gender" value="m">Male<br>
<input type="radio" name="gender" value="f">Female<br>[/HTML]
If you have a list of radio buttons with the same name then the user can only choose one from that list. So here they can choose one option from the 'choose_food" options and one option from the "gender" option.

When the user submits the form all of the stuff that they entered will be stored by PHP in $_POST (if your form tag is <form method="POST">)
So the gender they chose will be stored in $_POST['gender'] and the food they chose will be stored in $_POST['choose_food'].
May 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.