tags:

views:

39

answers:

4

what i want to do is that when you vote Y or N (two different radio buttons) and then it inserts into the "vote" column(in database) = Y or N(what you pickd), if nothing then echo error.

I know how to do this like halfway, i never worked with radiobuttons before so i need you guys.

Here's a two radio button right:

Yes: <input type="radio" value="Y" id="voteYes" name="vote"></input>  <br>
No: <input type="radio" value="N" id="voteNo" name="vote"> </input>

I gave the value N and Y, not the same ID, but the same name. I think its right, but how should i do with the PHP part of what i want to do? I mean shall i call for "vote"? ($_GET["vote"]) i dont think so.. here's where im stuck

A: 

Why not? Just make sure you validate your data... make sure $_GET['vote'] must be an element of array('Y', 'N'), if true you insert it, else echo error and you're done.

greg0ire
A: 

POST variables are found in $_POST.

echo $_POST['vote'];
Ignacio Vazquez-Abrams
A: 

You're almost there. Depending on whether or not your form uses the GET or POST method, you'll have to change the variable name appropriately.

if(isset($_GET["vote"])) //checks to see if the user inputed something
{
    $value = $_GET["vote"]; //remember, this value is not guaranteed to be either Y or N
}
else
{
    //display your error
}
Tim Cooper
A: 

It depends on the method used. If you POST the form, then the variable will be $_POST['vote'], if you GET the form (default) then it will be $_GET['vote'].

Specify the method used in the form tag:

<form action="foo.php" method="POST">

or...

<form action="foo.php" method="GET">

Check for the existance of the variable either with isset() or array_key_exists().

nikc