Page 1 of 1

whats wrong with this code?

Posted: Sat Oct 01, 2005 4:52 pm
by tail
im trying to make a basic script that has a input box for their name and two radio buttons and when you submit it will say something like:

radio 1 checked:

haha, NAME, get a life

radio 2 checked:

good job, NAME, you have a life

this is what i have so far:

Page 1:

Code: Select all

<html>
<head>
<title>Testing Page</title>
</head>
<body>
<form action="tail2.php" method="POST">
Enter your name: <input type="text" name="name" /><br><br>
<p>Do you have a life?<br><br>
yes
<input name="button1" value="yes" type="radio" id="button1"></p>
<p>no<input name="button1" value="no" type="radio" id="button1"></p>
<input name="Get Code!" type="submit" id="Get Code!" value="Find out what I have to say" />
</form> 
</body>
</html>
Page 2:

Code: Select all

<html>
<head>
<title>Testing Page 2</title>
</head>
<body>
<?php
if($button1 == "yes"){
    $no1="haha, ["name"], get a life";}
	echo"$no1";
	?><br><br>
	<?php
if($button1 == "no"){
    $b2="good job, ["name"], you have a life";}
echo"$b2";
?>
	<?php
if($button1 == ""){
    $b3="Select something homo";}
echo"$b3";
?>
</html>
any help?

Posted: Sat Oct 01, 2005 4:59 pm
by anthony88guy
when using POST to transfer data from a form the data will be contained in this variable $_POST['inputnamehere'] same goes for GET so you would use $_GET['inputnamehere'].

For your code try this:

Code: Select all

<html>
<head>
<title>Testing Page 2</title>
</head>
<body>
<?php
if($_POST['button1'] == "yes"){
    $no1="haha, " . $_POST['name'] . ", get a life";}
   echo"$no1";
   ?><br><br>
   <?php
if($_POST['button1'] == "no"){
    $b2="good job, " . $_POST['name'] . ", you have a life";}
echo"$b2";
?>
   <?php
if($_POST['button1'] == ""){
    $b3="Select something homo";}
echo"$b3";
?>
</html>
EDIT: Remember never trust the users input data.

Posted: Sat Oct 01, 2005 5:05 pm
by tail
thanks :)