radio form submission

radio form submission

am 23.06.2011 20:18:52 von Chris Stinemetz

So far I am good on creating the form and submitting it to mysql
database and calling the submitting value from a different script.

My question is: How can I make it so when a user selects radio option
value "1" it will then be displayed as 0-250kbps when I call it the
value in the bottom script?

forgive my indention. Gmail messes it up.


#### My Form ####


echo '


Store name:


Market:';

echo '

';

echo 'Broadband speed test results:


0-250kbps|
250-300kbps|
300-400kbps|
400-600kbps|
600kbps-3.8mbps />


Store visit details:






';

#### My display script ####

$posts_sql = "SELECT
posts.post_store,
posts.post_content,
posts.post_tptest,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
ORDER BY
posts.post_date DESC ";

$posts_result = mysql_query($posts_sql);

if(!$posts_result)
{
echo 'The posts could not be displayed, please try again
later.';
}
else
{

while($posts_row = mysql_fetch_assoc($posts_result))
{
echo '
' . $posts_row['first_name'] . ' ' .
$posts_row['last_name'] . '
' . date('m-d-Y h:iA',
strtotime($posts_row['post_date'])) . '
' . $posts_row['post_tptest'] .
'
' . htmlentities(stripslashes($posts_row['post_content'])) .
'
';
}
}

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 20:44:51 von nagendra802000

--000e0cd4849ef039af04a6657ace
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

I guess if you are storing the value of "post_tptest" in the database, it
should return the same value what the user selected in the radio option. If
I am right in your display you are just calling the data from the database.
Check if the data is properly storing the radio button values in the
database ??



--=20
*Best,
*
*Guru=99*

--000e0cd4849ef039af04a6657ace--

Re: radio form submission

am 23.06.2011 20:47:32 von Jim Giner

Try reading a good html reference on how radio buttons work.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 20:47:46 von daniel.brown

On Thu, Jun 23, 2011 at 14:18, Chris Stinemetz w=
rote:
> So far I am good on creating the form and =A0submitting it to mysql
> database and calling the submitting value from a different script.
>
> My question is: How can I make it so when a user selects radio option
> value "1" it will then be displayed as 0-250kbps when I call it the
> value in the bottom script?

Use an if or a switch. For example:


// Using if/elseif/else

if ($row['tp_test'] == '1') {
echo '0-250Kbps';
} elseif ($row['tp_test'] == '2') {
echo 'The second value.';
} elseif ($row['tp_test'] == '3') {
echo 'The third value.';
} else {
echo 'I have no clue. I give up.';
}


// Using switch

switch ($row['tp_test']) {
case '1':
echo 'First case.';
break;
case '2':
echo 'Second case.';
break;
case '3':
echo 'Third case.';
break;
default:
echo 'No idea whatsoever.';
break;
}

?>

--=20

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 21:32:53 von Karl DeSaulniers

--Apple-Mail-1--162107655
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Try this...

function getSpeed($val) {
if($val != 'undefined') {
switch ($val){
case "1":
$post_tptest = "0-250kbps";
break;
case "2":
$post_tptest = "250-300kbps";
break;
case "3":
$post_tptest = "300-400kbps";
break;
case "4":
$post_tptest = "400-600kbps";
break;
case "5":
$post_tptest = "600kbps-3.8mbps";
break;
default:
$post_tptest = "Speed Undetected"; // or "0-250kbps"
break;
}
} else {
return("Error, no speed value set");
}
}
}

$post_speed = getSpeed($post_tptest);

$posts_sql = "SELECT
posts.post_store,
posts.post_content,
posts.post_speed,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
ORDER BY
posts.post_date DESC ";

....

Best,
Karl


On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:

> So far I am good on creating the form and submitting it to mysql
> database and calling the submitting value from a different script.
>
> My question is: How can I make it so when a user selects radio option
> value "1" it will then be displayed as 0-250kbps when I call it the
> value in the bottom script?
>
> forgive my indention. Gmail messes it up.
>
>
> #### My Form ####
>
>
> echo '


> Store name:
> >

> Market:';
>
> echo '

';
>
> echo 'Broadband speed test results:


> 0-250kbps|
> 250-300kbps|
> 300-400kbps|
> 400-600kbps|
> 600kbps-3.8mbps > />


> Store visit details:


>


>
>
';
>
> #### My display script ####
>
> $posts_sql = "SELECT
> posts.post_store,
> posts.post_content,
> posts.post_tptest,
> posts.post_date,
> posts.post_by,
> users.user_id,
> users.user_name,
> users.first_name,
> users.last_name
> FROM
> posts
> LEFT JOIN
> users
> ON
> posts.post_by = users.user_id
> WHERE
> posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
> ORDER BY
> posts.post_date DESC ";
>
> $posts_result = mysql_query($posts_sql);
>
> if(!$posts_result)
> {
> echo 'The posts could not be displayed, please try again
> later.';
> }
> else
> {
>
> while($posts_row = mysql_fetch_assoc($posts_result))
> {
> echo '
> ' . $posts_row['first_name'] . ' ' .
> $posts_row['last_name'] . '
' . date('m-d-Y h:iA',
> strtotime($posts_row['post_date'])) . '
> ' . $posts_row['post_tptest'] .
> '
' . htmlentities(stripslashes($posts_row['post_content'])) .
> '
> ';
> }
> }
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-1--162107655--

Re: radio form submission

am 23.06.2011 21:46:02 von Chris Stinemetz

>
> =A0 =A0Use an if or a switch. =A0For example:
>

I think your suggestions are exactly what I am looking for. I am not
sure exactly where to place it. Do I insert it after the query
statment?

Thank you,

Chris

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 21:49:47 von daniel.brown

On Thu, Jun 23, 2011 at 15:46, Chris Stinemetz w=
rote:
>>
>> =A0 =A0Use an if or a switch. =A0For example:
>>
>
> I think your suggestions are exactly what I am looking for. I am not
> sure exactly where to place it. Do I insert it after the query
> statment?

During your while() loop. This line here:

' . $posts_row['post_tptest'] .

If you convert it to a function as Karl suggested, you could do
something like this:

' . getSpeed($posts_row['post_tptest']) =
..

--=20

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 22:08:56 von Chris Stinemetz

On Thu, Jun 23, 2011 at 2:49 PM, Daniel P. Brown
wrote:
> On Thu, Jun 23, 2011 at 15:46, Chris Stinemetz =
wrote:
>>>
>>> =A0 =A0Use an if or a switch. =A0For example:
>>>
>>
>> I think your suggestions are exactly what I am looking for. I am not
>> sure exactly where to place it. Do I insert it after the query
>> statment?
>
> =A0 =A0During your while() loop. =A0This line here:
>
> =A0 =A0 =A0 =A0' . $posts_row['post_tptest'] .
>
> =A0 =A0If you convert it to a function as Karl suggested, you could do
> something like this:
>
> =A0 =A0 =A0 =A0' . getSpeed($posts_row['post_t=
ptest']) .
>

I must be missing something. I am just getting a blank page. Your help
is greatly apprecieated.

The function and query statement is:

function getSpeed($val) {
if($val !=3D 'undefined') {
switch ($val){
case "1":
$post_tptest =3D "0-250kbps";
break;
case "2":
$post_tptest =3D "250-300kbps";
break;
case "3":
$post_tptest =3D "300-400kbps";
break;
case "4":
$post_tptest =3D "400-600kbps";
break;
case "5":
$post_tptest =3D "600kbps-3.8mbps";
break;
default:
$post_tptest =3D "Speed Undetected"; // or "0-2=
50kbps"
break;
}
} else {
return("Error, no speed value set");
}
}
}

$post_speed =3D getSpeed($post_tptest);
=09
//fetch the posts from the database
$posts_sql =3D "SELECT
posts.post_store,
posts.post_content,
posts.post_speed, =09
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by =3D users.user_id
WHERE
posts.post_store =3D " . mysql_real_escape_string($_GET['id']) . "
ORDER BY
posts.post_date DESC ";=09
=09

The call:

while($posts_row =3D mysql_fetch_assoc($posts_result))
{
echo '
' . $posts_row['first_name'] . ' ' .
$posts_row['last_name'] . '
' . date('m-d-Y h:iA',
strtotime($posts_row['post_date'])) . '
' .
getSpeed($posts_row['post_tptest']) . '
' .
htmlentities(stripslashes($posts_row['post_content'])) . '
';
}
}


Thank you!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 22:12:03 von daniel.brown

T24gVGh1LCBKdW4gMjMsIDIwMTEgYXQgMTY6MDgsIENocmlzIFN0aW5lbWV0 eiA8Y2hyaXNzdGlu
ZW1ldHpAZ21haWwuY29tPiB3cm90ZToKPgo+IEkgbXVzdCBiZSBtaXNzaW5n IHNvbWV0aGluZy4g
SSBhbSBqdXN0IGdldHRpbmcgYSBibGFuayBwYWdlLiBZb3VyIGhlbHAKPiBp cyBncmVhdGx5IGFw
cHJlY2llYXRlZC4KCiAgICBUaGlzIGlzIHdoeSB5b3UncmUgc3VwcG9zZWQg dG8gdGFrZSB0aGUg
YWR2aWNlIGFuZCB3cml0ZSBpdCBvdXQKeW91cnNlbGYsIG5vdCBjb3B5IGFu ZCBwYXN0ZSB0aGUg
Y29kZS4gIDstUAoKICAgIEJ5IGNvcHlpbmcgYW5kIHBhc3RpbmcgdGhlIHN0 dWZmLCB5b3UgYnJv
a2UgeW91ciBxdWVyeS4gIEthcmwKc3VnZ2VzdGVkIHlvdSB1c2UgYSBjb2x1 bW4gd2hpY2ggZG9l
c24ndCBleGlzdC4gIEluc3RlYWQsIGNoYW5nZSB0aGUKcXVlcnkgYmFjayB0 byB3aGF0IGl0IHdh
cyBiZWZvcmUsIGFkZCB0aGUgZnVuY3Rpb24gKHlvdSBzaG91bGQgYmUgYWJs ZQp0byBjb3B5IGFu
ZCB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CgIKAgoCCgIKAgoCCgIKAg oCCgIKAgoCCgIKAg
oCCgIKAgoCCgPHRkIGNsYXNzPSJ1c2VyLXBvc3QiPicgLiAkcG9zdHNfcm93 WydmaXJzdF9uYW1l
J10gLiAnICcgLgo+ICRwb3N0c19yb3dbJ2xhc3RfbmFtZSddIC4gJzxici8+ JyAuIGRhdGUoJ20t
ZC1ZIGg6aUEnLAo+IHN0cnRvdGltZSgkcG9zdHNfcm93Wydwb3N0X2RhdGUn XSkpIC4gJzwvdGQ+
Cj4goCCgIKAgoCCgIKAgoCCgIKAgoCCgIKAgoCCgIKAgoCCgIKAgoCCgIKAg oCCgIKAgoCCgIKAg
oDx0ZCBjbGFzcz0icG9zdC1jb250ZW50Ij4nIC4KPiBnZXRTcGVlZCgkcG9z dHNfcm93Wydwb3N0
X3RwdGVzdCddKSAuICc8YnIvPicgLgo+IGh0bWxlbnRpdGllcyhzdHJpcHNs YXNoZXMoJHBvc3Rz
X3Jvd1sncG9zdF9jb250ZW50J10pKSAuICc8L3RkPgo+IKAgoCCgIKAgoCCg IKAgoCCgIKAgoCCg
IKAgoCCgIKAgoCCgIKAgoCCgIKAgoCCgIKA8L3RyPic7Cj4goCCgIKAgoCCg IKAgoCCgIKAgoCCg
IKAgoCCgIKAgoH0KPiCgIKAgoCCgIKAgoCCgIKAgoCCgIKAgoH0KPgo+Cj4g VGhhbmsgeW91IQo+
CgoKCi0tIAo8L0RhbmllbCBQLiBCcm93bj4KRGVkaWNhdGVkIFNlcnZlcnMs IENsb3VkIGFuZCBD
bG91ZCBIeWJyaWQgU29sdXRpb25zLCBWUFMsIEhvc3RpbmcKKDg2Ni0pIDcy NS00MzIxCmh0dHA6
Ly93d3cucGFyYXNhbmUubmV0Lwo=

Re: radio form submission

am 23.06.2011 22:17:07 von Jim Giner

If you put the "0-250kbps" as the value= of your html tag, php would
give you that when you did this:

$rb_picked = $_POST['post_tptest'].

No need for a switch or anything to re-interpret what the user picked.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 23.06.2011 22:19:00 von Karl DeSaulniers

I also think you need to use the mysql_free_result like so..

echo '

';

If I am incorrect, please, someone interject. :)

Best,
Karl

On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:

> echo '

';

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: radio form submission

am 24.06.2011 02:41:12 von Tamara Temple

On Jun 23, 2011, at 2:32 PM, Karl DeSaulniers wrote:

> Try this...
>
> function getSpeed($val) {
> if($val != 'undefined') {
> switch ($val){
> case "1":
> $post_tptest = "0-250kbps";
> break;
> case "2":
> $post_tptest = "250-300kbps";
> break;
> case "3":
> $post_tptest = "300-400kbps";
> break;
> case "4":
> $post_tptest = "400-600kbps";
> break;
> case "5":
> $post_tptest = "600kbps-3.8mbps";
> break;
> default:
> $post_tptest = "Speed Undetected"; // or "0-250kbps"
> break;
> }
> } else {
> return("Error, no speed value set");

Just to point out, this is the only return from this function. The
$post_tptest is never returned. You could actually just say:

return "0-250kbps";

above instead of setting the $post_tptest *local* variable. (You
wouldn't need the break statements, then, either, but it's still
probably a good idea to code them in.)

> }
> }
> }
> $post_speed = getSpeed($post_tptest);
>

Or, you know, an array:

speed = array(
'1'=>'0-250kbps',
'2'=>'250-300kbps'.
'3'=>'300-400kbps',
'4'=>'400-600kbps',
'5'=>'600kbps-3.8mbps',
);

//$post_speed = isset($speed[$post_tptest])?
$speed[$post_tptest]:"Speed undetected";

(See below for inline usage.)

Of course, you could also avoid all this translation by putting the
string values you want in the radio button on the form itself. This
may have implications for your database and how you store it, however.

You can also avoid the problem with an empty return if no radio button
is checked by making sure one is checked when your form loads, by
using the 'checked' attribute on one of the items. If you want them to
have a "not tested" option, you can include that as one of your
buttons and add it to the array above as well. (That might be a good
place to use the zero value.)


>
> $posts_sql = "SELECT
> posts.post_store,
> posts.post_content,
> posts.post_speed,
> posts.post_date,
> posts.post_by,
> users.user_id,
> users.user_name,
> users.first_name,
> users.last_name
> FROM
> posts
> LEFT JOIN
> users
> ON
> posts.post_by = users.user_id
> WHERE
> posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
> ORDER BY
> posts.post_date DESC ";
>
> ...
>
> Best,
> Karl
>
>
> On Jun 23, 2011, at 1:18 PM, Chris Stinemetz wrote:
>
>> So far I am good on creating the form and submitting it to mysql
>> database and calling the submitting value from a different script.
>>
>> My question is: How can I make it so when a user selects radio option
>> value "1" it will then be displayed as 0-250kbps when I call it the
>> value in the bottom script?
>>
>> forgive my indention. Gmail messes it up.
>>
>>
>> #### My Form ####
>>
>>
>> echo '


>> Store name:
>> >

>> Market:';
>>
>> echo '

';
>>
>> echo 'Broadband speed test results:


>> 0-250kbps|
>> 250-300kbps|
>> 300-400kbps|
>> 400-600kbps|
>> 600kbps-3.8mbps >> />


>> Store visit details:


>>


>>
>>
';
>>
>> #### My display script ####
>>
>> $posts_sql = "SELECT
>> posts.post_store,
>> posts.post_content,
>> posts.post_tptest,
>> posts.post_date,
>> posts.post_by,
>> users.user_id,
>> users.user_name,
>> users.first_name,
>> users.last_name
>> FROM
>> posts
>> LEFT JOIN
>> users
>> ON
>> posts.post_by = users.user_id
>> WHERE
>> posts.post_store = " .
>> mysql_real_escape_string($_GET['id']) . "
>> ORDER BY
>> posts.post_date DESC ";
>>
>> $posts_result = mysql_query($posts_sql);
>>
>> if(!$posts_result)
>> {
>> echo 'The posts could not be displayed, please try again
>> later.';
>> }
>> else
>> {
>>
>> while($posts_row = mysql_fetch_assoc($posts_result))
>> {
>> echo '
>> ' . $posts_row['first_name'] . ' ' .
>> $posts_row['last_name'] . '
' . date('m-d-Y h:iA',
>> strtotime($posts_row['post_date'])) . '
>> ' . $posts_row['post_tptest'] .

Here is where you'd use the speed array we defined above:

' .
(isset($speed[($posts_row['post_tptest'])])?
$speed[($posts_row['post_tptest'])]:"Speed undetected") .

>> '
' . htmlentities(stripslashes($posts_row['post_content'])) .
>> '
>> ';
>> }
>> }
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: radio form submission

am 24.06.2011 10:18:27 von Karl DeSaulniers

Hi Chris,
Here is the corrected code. Yes, call the function before the SQL
SELECT like so.
You may have to work with it a bit. This was just off the top of the
head.

But now that I look at it, I think Jim may be right.
What's the purpose of the inputs having 1, 2, 3, etc and not the
0-250kbps, etc?
If there is no purpose, I would make the values of the inputs the
values you want to store in your database.
Muuch easier..

Otherwise try this. You should be able to copy an paste.

//your form code...

function getSpeed($val) {
if($val != 'undefined') {
switch ($val) {
case "1":
$post_speed = "0-250kbps";
break;
case "2":
$post_speed = "250-300kbps";
break;
case "3":
$post_speed = "300-400kbps";
break;
case "4":
$post_speed = "400-600kbps";
break;
case "5":
$post_speed = "600kbps-3.8mbps";
break;
default:
$post_speed = "Speed Undetected"; // or "0-250kbps"
break;
}
return $post_speed;
} else {
die("Error, no speed value set");
}
}

//This part may need to be worked. Basically you want;
posts.post_tptest to equal the result of getSpeed($_POST
['post_tptest']).
//however you can get it there in your code. Or just try this, see if
this works and go from there.

$_POST['post_tptest'] = getSpeed($_POST['post_tptest']);

$posts_sql = "SELECT
posts.post_store,
posts.post_content,
posts.post_tptest,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
ORDER BY
posts.post_date DESC ";

//... rest of your code

HTH,
GL,
Best,

Karl

On Jun 23, 2011, at 3:17 PM, Jim Giner wrote:

> If you put the "0-250kbps" as the value= of your html tag,
> php would
> give you that when you did this:
>
> $rb_picked = $_POST['post_tptest'].
>
> No need for a switch or anything to re-interpret what the user picked.
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: radio form submission

am 24.06.2011 13:28:10 von Chris Stinemetz

Thanks everyone.

> If there is no purpose, I would make the values of the inputs the values you
> want to store in your database.
> Muuch easier..
>

So I am trying to keep this simple and just assign the value with the
radio button and then insert it into mysql database, but with the
following code I am getting the mysql error: Unknown column '250kbps'
in 'field list' when I choose the first radio button.

I think it has to do with the value being a string, but I haven't been
able to figure out the fix.

Thanks everyone for your help in accomplishing one thing with many
differnt techniques. It is greatly appreciated.

Chris

#### Form ####

echo '


Store name:


Market:';

echo '

';

echo 'Broadband speed test results:


0-250kbps|
250-300kbps|
300-400kbps|
400-600kbps|
600kbps-3.8mbps value="600kbps-3.8mbps" />


Store visit details:






';
}
}
}


#### Insert Code ####

$sql = "INSERT INTO
posts(post_content,
post_date,
post_tptest,
post_store,
post_by)
VALUES
('" . mysql_real_escape_string($_POST['post_content']) . "',
NOW(),
" . $_POST['post_tptest'] . ",
" . $storeid . ",
" . $_SESSION['user_id'] . "
)";
$result = mysql_query($sql);

if(!$result)
{
//something went wrong, display the error
echo 'An error occured while inserting your post. Please try
again later.

' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
$sql = "COMMIT;";
$result = mysql_query($sql);

//after a lot of work, the query succeeded!
echo 'You have succesfully created your new store visit.';
}
}
}
}
}

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: radio form submission

am 24.06.2011 16:18:03 von Jim Giner

The error is pretty explicit - there is no field in your table called
'250kbps'. What you should have is a field (column) called "speed" for
example, with values from 1...5 or whatever. To the users they will only
deal with actual speed values on their screen if you use the speeds as the
value parms of your html. To you, the programmer, yes - you could use a
switch statement to convert the incoming radio button value to a 1 or 2 or
3, etc. and store that value to the "speed" column or not. I'm thinking
that you are trying to store each radio button to its own column in your
table which is not good, normalized structure.

"Chris Stinemetz" wrote in message
news:BANLkTi=jA+YeEGwCSvwBcjeb6WP1gG6M=g@mail.gmail.com...
> Thanks everyone.
>
> So I am trying to keep this simple and just assign the value with the
> radio button and then insert it into mysql database, but with the
> following code I am getting the mysql error: Unknown column '250kbps'
> in 'field list' when I choose the first radio button.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php