Radio Button Variables to MySQL

This is a discussion on Radio Button Variables to MySQL within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I have a simple question, I am new to PHP Programming. I want to make a simple survey and ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-06-2004
Deutscher
 
Posts: n/a
Default Radio Button Variables to MySQL

Hello,

I have a simple question, I am new to PHP Programming. I want to make a
simple survey and insert the data into a MySQL Server. The data gets into
the database fine, but I do not get the VALUE of the selected radio button.
Instead what I get under the fields of the table is the NAME value. Example
like:

Table: gender_survey
Field: GENDER Data: GENDER

What I want is:

Table: gender_survey
Field: GENDER Data: MALE -OR- FEMALE depending on the radio button selected.

-----------------------form.html-----------------------
<form method="POST" action="collect.php">
Gender: Male <input type="radio" value="MALE" name="Gender"> Female<input
type="radio" value="FEMALE" name="Gender">
<input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"
</form>
---------------------------------------------------------
-----------------------collect.php-----------------------
Danke für Ihre Meinung!

<?
$username="USERNAME";
$password="PASSWORD";
$database="test";

$Gender=array('MALE','FEMALE');
$Gender=$_POST['Gender'];

mysql_connect("10.33.39.252",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";
mysql_query($query);

mysql_close();
?>
-----------------------------------------------------------


Danke Schön!


Reply With Quote
  #2 (permalink)  
Old 09-06-2004
Alvaro G Vicario
 
Posts: n/a
Default Re: Radio Button Variables to MySQL

*** Deutscher wrote/escribió (Mon, 06 Sep 2004 04:29:20 GMT):
> Instead what I get under the fields of the table is the NAME value.


You never use the variable. You insert a constant string:

INSERT INTO geschlechts_umfragen VALUES ('Gender')

> $Gender=array('MALE','FEMALE');


What's this, the remainings of a test?

> $Gender=$_POST['Gender'];
> $query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";


$query = "INSERT INTO geschlechts_umfragen VALUES ('" .
mysql_escape_string($Gender) . "')";

--
-- Álvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Reply With Quote
  #3 (permalink)  
Old 09-07-2004
Breaker One
 
Posts: n/a
Default Re: Radio Button Variables to MySQL

Deutscher wrote:
> Hello,
>
> I have a simple question, I am new to PHP Programming. I want to make a
> simple survey and insert the data into a MySQL Server. The data gets into
> the database fine, but I do not get the VALUE of the selected radio button.
> Instead what I get under the fields of the table is the NAME value. Example
> like:
>
> Table: gender_survey
> Field: GENDER Data: GENDER
>
> What I want is:
>
> Table: gender_survey
> Field: GENDER Data: MALE -OR- FEMALE depending on the radio button selected.
>
> -----------------------form.html-----------------------
> <form method="POST" action="collect.php">
> Gender: Male <input type="radio" value="MALE" name="Gender"> Female<input
> type="radio" value="FEMALE" name="Gender">
> <input type="submit" value="Submit" name="B1"><input type="reset"
> value="Reset" name="B2"
> </form>
> ---------------------------------------------------------
> -----------------------collect.php-----------------------
> Danke für Ihre Meinung!
>
> <?
> $username="USERNAME";
> $password="PASSWORD";
> $database="test";
>
> $Gender=array('MALE','FEMALE');
> $Gender=$_POST['Gender'];
>
> mysql_connect("10.33.39.252",$username,$password);
> @mysql_select_db($database) or die( "Unable to select database");
>
> $query = "INSERT INTO geschlechts_umfragen VALUES ('Gender')";
> mysql_query($query);
>
> mysql_close();
> ?>
> -----------------------------------------------------------
>
>
> Danke Schön!
>
>


You may want to put a $ by gender in $query.. right?
Reply With Quote
  #4 (permalink)  
Old 09-08-2004
RootShell
 
Posts: n/a
Default Re: Radio Button Variables to MySQL

$query = "INSERT INTO geschlechts_umfragen VALUES ('$Gender')";

--
ZXSpectrum "Name The Game" - Can you guess the name of ZXSpectrum games,
just by looking at a ingame picture? Well you can find out if you can (or
not) at.... http:/ntg.docaj.net
--


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:06 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0