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 '
';
#### 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.
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;
}
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 '
';
> }
> }
>
> --
> 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:
--
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
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.)
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 '
';
>> }
>> }
>>
>> --
>> 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.
$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.
//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