473,386 Members | 1,647 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,386 software developers and data experts.

radio button in mysql

hello.

when I am creating a form using the PHP language, everything is going fine and I have the data stored in the sql database,
But when I add some radio button for example:

<body>
age:&nbsp; &lt;12
<input type="radio" value="V1" name="12" />
&nbsp;&nbsp;&nbsp; 13 - 18
<input type="radio" name="13-18" value="V2" />
&nbsp;&nbsp;&nbsp; 19 and up
<input type="radio" name="13-18" value="V3" />

</body>



how can I let them be stored in the sql?
need help plz!! thx in advance,
Dec 28 '07 #1
8 4055
Markus
6,050 Expert 4TB
hello.

when I am creating a form using the PHP language, everything is going fine and I have the data stored in the sql database,
But when I add some radio button for example:

<body>
age:&nbsp; &lt;12
<input type="radio" value="V1" name="12" />
&nbsp;&nbsp;&nbsp; 13 - 18
<input type="radio" name="13-18" value="V2" />
&nbsp;&nbsp;&nbsp; 19 and up
<input type="radio" name="13-18" value="V3" />

</body>



how can I let them be stored in the sql?
need help plz!! thx in advance,
Radio buttons cannot be stored in the database... shame, i know! I'd store a whole form in there if i could - pen included! The value of said radio button, however, can be. [php]$radio = $_POST['name_of_radio_button'];[/php]:)
Dec 29 '07 #2
zlash
9
It should be noted that radio buttons from the same group, should have the same element name. So radio buttons for A , B and C can have "value" attributes of 'A','B' and 'C' respectively but the same "name" attribute, something like 'letter'.

So you will always receive the 'letter' key on the $_POST or $_GET array with the value of the option chosen.
Dec 29 '07 #3
Markus
6,050 Expert 4TB
It should be noted that radio buttons from the same group, should have the same element name. So radio buttons for A , B and C can have "value" attributes of 'A','B' and 'C' respectively but the same "name" attribute, something like 'letter'.

So you will always receive the 'letter' key on the $_POST or $_GET array with the value of the option chosen.
<input type="radio" name="name_For[]" />
Creates an array which you can use in php - which is what zlash is talking about... i think.
Dec 29 '07 #4
I m not sure what "ilikephp" is after but hope this can help him

For example :

I have purchase table that has 4 fields :

Id,Quantity,PricePerItem, TotalCost

[PHP]<?
$sql = "SELECT * FROM purchase order by id";
$result = mysql_query($sql);

echo "<TABLE borderColor=#cccccc cellSpacing=0 cellPadding=0 align=center border=1>
<TBODY>
<TR align=middle bgColor=#ffffff>
<TD width=115 height=20>
<DIV align=center><STRONG><span class=\"o\"><b><font color=\"#000080\">Options</font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><STRONG><span class=\"o\"><b><font color=\"#000080\">Quantity</font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><STRONG><span class=\"o\"><b><font color=\"#000080\">Price Per Item </font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><STRONG><span class=\"o\"><b><font color=\"#000080\">Total Cost</font></b></span></STRONG></DIV></TD></TR>";

while ($row = mysql_fetch_assoc($result)) {

echo "<TR vAlign=center align=middle bgColor=#eaeaea>
<td><input type=\"radio\" value=\"$row[TotalCost]\" name=\"R1\"></td>
<TD width=115 bgColor=#edf2fb height=20>
<DIV align=center><span class=\"o\"><font color=\"#000080\">$row[Quanity]</font></span></DIV></TD>
<TD width=115 bgColor=#edf2fb height=20>
<DIV align=center><span class=\"o\"><font color=\"#000080\">$row[PricePerItem]</font></span></DIV></TD>
<TD width=115 bgColor=#edf2fb height=20>
<DIV align=center><span class=\"o\"><font color=\"#000080\">$$row[TotalCost]</font></span></DIV></TD></TR>";

}
}

echo "</TBODY></TABLE>";

?>[/PHP]
Dec 30 '07 #5
Hello guys ;)

THANKS a lot for your help,
but because I am new in PHP language and SQL, I find difficulties in doing the form. So I made a copy for the whole form, if you can please help me in the script that I should type in the sql server and in the php in order to make a link between them and the information will be stored. (so I can copy and paste it)
THANKS in advance !! :)



<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>FORM</strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td>Age</td>
<td>:</td>
<td><label>
<input name="radiobutton" type="radio" value="radiobutton" />
&lt; 12
<input name="radiobutton" type="radio" value="radiobutton" />
13 - 18
<input name="radiobutton" type="radio" value="radiobutton" />
18 and up</label></td>
</tr>
<tr>
<td>gender</td>
<td>:</td>
<td><label>
male
<input name="gender" type="radio" value="m" />
female
<input name="gender" type="radio" value="f" />
</label></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Jan 3 '08 #6
Markus
6,050 Expert 4TB
One thing you will not get from tsdn is code written for you.

To retrieve the form you use $_POST

i.e
[php]
$username = $_POST['username'];
/* username is the name of the input of previus page */
$email = $_POST['email'];
/* email is the name of the input of previous page */
$comment = $_POST['comment'];
/* ... */

//code for mysql connection and insert here **
[/php]

** A good tutorial for connecting to mysql and insert/update/deleting data can be found here

:)
Jan 3 '08 #7
Hello,

You may create a mysql.php file that will store your connection information and then add this file mysql.php to the guestbook.php which contains the form

mysql.php file

[PHP]<?

$server = 'localhost';
$database = 'guestbook';
$username = 'root';
$password = 'root';
$connection = mysql_connect($server,$username,$password);

if (!$connection) {
die('Could not connect to MySQL database, the server return the error: '.mysql_error());
}
$db = @mysql_select_db($database);

mysql_close();

?>[/PHP]

The in the guestbook.php you will include this line on top

[PHP]<?
include "mysql.php";
...

?>[/PHP]

Hope this helps
Jan 3 '08 #8
Thanks a lot,
but please I still need the code that I should put it in MySQL server.

and especially the code for the form that includes "age"

Thanks... :)
Jan 4 '08 #9

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

Similar topics

2
by: Mark Haase | last post by:
Hey All-- I'm rusty on my JavaScript but I'm pulling it back out to do a PHP/MySQL database application. I'm doing all the validation in PHP, but I'm using JavaScript to show/hide questions...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
7
by: help4me | last post by:
Hope someone can help me out with this. I'm having trouble getting my radio button values into a MySQL database. And after I do get them inserted I'm going to want to be able to show them back in...
1
by: Lazairus | last post by:
simply how do you set enums in a database using coorsoponding radio button from a html form now i have a table client_membership in mysql with the membership_type enum('six','one') i...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.