Click to See Complete Forum and Search --> : Help With Radios :)


mitchell
11-06-2007, 03:54 PM
i am planning to make a user on sign-up have a choice what he wants of something which he can only pick one off.
and then it passes onto the database feild either the number,1,2,3,4,5 depending which one of the 5 choices he picks.
i know how to do all the database stuff but im trying to do the form, and how i can put "this button means value 1 etc." this is what i have so far

echo ("<TR>
<TD>pick your land</TD>
<TD><INPUT TYPE = "radio" NAME="Q1" VALUE = "1">option 1<TD>
<INPUT TYPE = "radio" NAME="Q1" VALUE = "2">option 2</TD>
<TD><INPUT TYPE = "radio" NAME="Q1" VALUE = "3">option 3<TD>
<INPUT TYPE = "radio" NAME="Q1" VALUE = "4">option 4</TD>
<INPUT TYPE = "radio" NAME="Q1" VALUE = "5">option 5<TD>
<INPUT TYPE = "radio" NAME="Q1" VALUE = "6">option 6</TD>
</TR>");



how can i do it so the user can only pick one plus what do i need to do so it passes on the value the user picks in the database.

this i confusing me a lot but any help is appreciated

if your woundering the submit button at the bottom of the page is this:

<input name=\"register\" type=\"submit\" value=\"Register\">

ShaReB
11-06-2007, 05:32 PM
well, you're using radio buttons so it's only one choice the user gonna make.

to get the value just use a variable with the element name like $Q1 in this ex.

to insert it into the db

//connect to your database
//specify the sql statement
$sql = "insert into table (table.field) values (". $Q1 . ")";
//if you're using mySQL use mysql_query(); to actually query the database
mysql_query($sql);


:)

mitchell
11-06-2007, 06:24 PM
so all i do is add $Q1 to this like so?:


$query = mysql_query("INSERT INTO users (username, password, email,time,z,h,Q1) VALUES('$username','$password','$email','$time','$z','$h','$Q1')")
or die(mysql_error());

how will it know what Q1 is?

TecBrat
11-06-2007, 10:41 PM
how will it know what Q1 is?

I think the assumption was that the SQL query was being performed by the action page that receives the data from your form.

Another assumption was that REGISTER_GLOBALS was on. If it is, then Q1 from the form sets $Q1 in the action page.

Otherwise, we have to retrieve it from the correct array:
Since the <form action=...> was not included in your code, we don't know if we need to tell you to to use $_POST['Q1'] or $_GET['Q1']. (try $Q1=$_POST['Q1'] or $Q1=$_GET['Q1'])

Does this make sense?