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: <12
<input type="radio" value="V1" name="12" />
&nb sp; 13 - 18
<input type="radio" name="13-18" value="V2" />
&nb sp; 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,
8 4124 Markus 6,050
Recognized Expert Expert
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: <12
<input type="radio" value="V1" name="12" />
&nb sp; 13 - 18
<input type="radio" name="13-18" value="V2" />
&nb sp; 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]:)
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.
Markus 6,050
Recognized Expert Expert
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.
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,Pri cePerItem, TotalCost
[PHP]<?
$sql = "SELECT * FROM purchase order by id";
$result = mysql_query($sq l);
echo "<TABLE borderColor=#cc cccc cellSpacing=0 cellPadding=0 align=center border=1>
<TBODY>
<TR align=middle bgColor=#ffffff >
<TD width=115 height=20>
<DIV align=center><S TRONG><span class=\"o\"><b> <font color=\"#000080 \">Options</font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><S TRONG><span class=\"o\"><b> <font color=\"#000080 \">Quantity</font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><S TRONG><span class=\"o\"><b> <font color=\"#000080 \">Price Per Item </font></b></span></STRONG></DIV></TD>
<TD width=115 height=20>
<DIV align=center><S TRONG><span class=\"o\"><b> <font color=\"#000080 \">Total Cost</font></b></span></STRONG></DIV></TD></TR>";
while ($row = mysql_fetch_ass oc($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><s pan class=\"o\"><fo nt color=\"#000080 \">$row[Quanity]</font></span></DIV></TD>
<TD width=115 bgColor=#edf2fb height=20>
<DIV align=center><s pan class=\"o\"><fo nt color=\"#000080 \">$row[PricePerItem]</font></span></DIV></TD>
<TD width=115 bgColor=#edf2fb height=20>
<DIV align=center><s pan class=\"o\"><fo nt color=\"#000080 \">$$row[TotalCost]</font></span></DIV></TD></TR>";
}
}
echo "</TBODY></TABLE>";
?>[/PHP]
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>FOR M</strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCC C">
<tr>
<form id="form1" name="form1" method="post" action="addgues tbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFF F">
<tr>
<td width="117">Nam e</td>
<td width="14">:</td>
<td width="357"><in put 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="radiobutt on" type="radio" value="radiobut ton" />
< 12
<input name="radiobutt on" type="radio" value="radiobut ton" />
13 - 18
<input name="radiobutt on" type="radio" value="radiobut ton" />
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">Co mment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Markus 6,050
Recognized Expert Expert
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
:)
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,$usernam e,$password);
if (!$connection) {
die('Could not connect to MySQL database, the server return the error: '.mysql_error() );
}
$db = @mysql_select_d b($database);
mysql_close();
?>[/PHP]
The in the guestbook.php you will include this line on top
[PHP]<?
include "mysql.php" ;
...
?>[/PHP]
Hope this helps
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... :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 which depend on the responses to other
questions, e.g. "If you answered yes to the previous question, then what
time of day will you need your service activated?"
One aspect of this is needing to be able to decide which radio button in
certain...
|
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 button with this
link of code:
echo 'SCRIPT language=JavaScript
setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //?
<snip of code>
|
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 MySQL database using JavaScript to find a product either by Product ID, Description, or Both. Originally, the 'Both' radio button was "checked" but I now want the 'Product ID' button set as the default choice (as you can see from the code below).
...
|
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 the form again (if the respondent didn't finish the whole form the first time). My text and textarea fields are inserting just fine and I'm able to bring those back up too. It's just the radio buttons that aren't working. When I created the table I...
|
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 have html corrosponding radio button
6 months
1 year
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |