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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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! |
|
|||
|
*** 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 ;-) -- |
|
|||
|
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? |
|
|||
|
$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 -- |