4 Replies - 541 Views - Last Post: 08 April 2012 - 12:58 PM Rate Topic: -----

#1 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Why won't my radio button display?

Posted 06 April 2012 - 05:00 PM

After the form is submit, it will not echo $genderRadio

Any ideas? It can select the gender but I can't display in the php file



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>

		<head>

			

			
			<title> Assignment 2</title>
			
		  


		</head>


					<body> 


							<h1>Please enter your information</h1>

									<form method= "post" action = "output_hw2.php">
									<table width="500">
									<tr>
									<td><strong>First Name:</strong> </td>
									<td><input type= "text" name = "fname" /></td>
									<tr/>
									<tr>
									<td><strong>Last Name:</strong></td>
									<td><input type="text" name = "lname" /></td>
									</tr>



									<tr>
									<td><strong>Gender:</strong></td> 
									<td></td>
									</tr>
									<tr>
									<td> <input type="radio" name = "genderRadio" value="Female" />Female</td>
									</tr>
									<td> <input type="radio" name = "genderRadio" value="Male"/>Male</td>
									</tr>

									<tr>
									<td><strong>Address:</strong> </td>
									<td><input type="text" name = "address" size="50"/></td>
									</tr>

									<tr>
									<td><strong>City:</strong> </td>
									<td><input type="text" name = "city" size="30"/></td>
									</tr>


									<tr>
									<td><strong>State:</strong></td> 


									<td><select name="state">
									<option value=" ">Pick a state</option>
									<option value="Ar">Arizona</option>
									<option value="GA">Georgia</option>
									<option value="TN">Tennessee</option></td>

									</select>
									</tr>
									<tr>
									<td><strong>Zip Code:</td>
									<td></strong> <input type="text" name="zip" size= "5" /></td>
									</tr>
									</table>

									<p><strong>Comments:</strong></p>
									<textarea name="comments" rows="5" cols="40" ></textarea> <br/><br/>

									<input type="submit" name="submit" value ="submit" /> <br/>

									</form>

					</body>


		</html>






here is the php code

<?php

$firstName = $_POST['fname']; 
$lastName  = $_POST['lname'];
$genderRadio   = $_POST['genderRadio'];
$address   = $_POST['address']; 
$state     = $_POST['state'];
$city      = $_POST['city']; 
$zip       = $_POST['zip']; 

echo "Thank You $firstName $lastName", "<br/>";
echo "<strong>This is what you entered </strong>: ". "<br/>"; 
echo "Address: <b>$address </b>". "<br/>";
echo "State: <b>$state</b> ". "City: <b>$city </b>". "Zip: <b>$zip</b> ". "<br/>";

echo "You are: $genderRadio ";
print "We are very please that you decided to submit your information. If you find anything
		wrong please go back and re-enter the correct information and please post a comment 
		saying that you're correcting your information in addition to the comment you already 
		add(if you did alread or want to add one)";  



?>


Is This A Good Question/Topic? 0
  • +

Replies To: Why won't my radio button display?

#2 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Re: Why won't my radio button display?

Posted 06 April 2012 - 05:52 PM

I have a code and I want to validate it before the submitting it. When I say before submitting it I mean that the form does not submit the information filled till everything is filled correctly. I was thinking of using the if statement but I believe if I do the information will still be sent to my database even the information might be incorrect. I also know that I probably have to use the empty() function.

Anyways, does anyone know how I can accomplish this? If they click on the submit button, I want to make sure everything is filled before sending the information to my database.



Here is my html code:
		</head>


					<body> 


							<h1>Please enter your information</h1>

									<form method= "post" action = "output_hw2.php">
									<table width="500">
									<tr>
									<td><strong>First Name:</strong> </td>
									<td><input type= "text" name = "fname" /></td>
									<tr/>
									<tr>
									<td><strong>Last Name:</strong></td>
									<td><input type="text" name = "lname" /></td>
									</tr>



									<tr>
									<td><strong>Gender:</strong></td> 
									<td></td>
									</tr>
									<tr>
									<td> <input type="radio" name = "genderRadio" value="Female" />Female</td>
									</tr>
									<td> <input type="radio" name = "genderRadio" value="Male"/>Male</td>
									</tr>

									<tr>
									<td><strong>Address:</strong> </td>
									<td><input type="text" name = "address" size="50"/></td>
									</tr>

									<tr>
									<td><strong>City:</strong> </td>
									<td><input type="text" name = "city" size="30"/></td>
									</tr>


									<tr>
									<td><strong>State:</strong></td> 


									<td><select name="state">
									<option value=" ">Pick a state</option>
									<option value="Ar">Arizona</option>
									<option value="GA">Georgia</option>
									<option value="TN">Tennessee</option></td>

									</select>
									</tr>
									<tr>
									<td><strong>Zip Code:</td>
									<td></strong> <input type="text" name="zip" size= "5" /></td>
									</tr>
									</table>

									<p><strong>Comments:</strong></p>
									<textarea name="comments" rows="5" cols="40" ></textarea> <br/><br/>

									<input type="submit" name="submit" value ="submit" /> <br/>

									</form>

					</body>


		</html>





Here is my Php file:

<?php

$firstName = $_POST['fname']; 
$lastName  = $_POST['lname'];
$genderRadio   = $_POST['genderRadio'];
$address   = $_POST['address']; 
$state     = $_POST['state'];
$city      = $_POST['city']; 
$zip       = $_POST['zip']; 

echo "Thank You $firstName $lastName", "<br/>";
echo "<strong>This is what you entered </strong>: ". "<br/>"; 
echo "Address: <b>$address </b>". "<br/>";
echo "State: <b>$state</b> ". "City: <b>$city </b>". "Zip: <b>$zip</b> ". "<br/>";

echo "You are: $genderRadio ";
print "We are very please that you decided to submit your information. If you find anything
		wrong please go back and re-enter the correct information and please post a comment 
		saying that you're correcting your information in addition to the comment you already 
		add(if you did alread or want to add one)";  



?>




Also
  • How can I get my $genderRadio to display
  • How can I make sure that everything is filled

Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2484
  • View blog
  • Posts: 8,517
  • Joined: 08-August 08

Re: Why won't my radio button display?

Posted 06 April 2012 - 07:27 PM

Forms are on the client side, so you could validate them with Javascript before submitting to the server where PHP would then need to revalidate because Javascript is not secure. When PHP finds that something is not valid it would need to resend the form with the data the user submitted and (an) error message(s). This makes the Javascript optional, as the only advantages are to make things a little easier for the user and take some small load off of the server.
Was This Post Helpful? 0
  • +
  • -

#4 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Re: Why won't my radio button display?

Posted 08 April 2012 - 12:12 PM

View PostCTphpnwb, on 06 April 2012 - 07:27 PM, said:

Forms are on the client side, so you could validate them with Javascript before submitting to the server where PHP would then need to revalidate because Javascript is not secure. When PHP finds that something is not valid it would need to resend the form with the data the user submitted and (an) error message(s). This makes the Javascript optional, as the only advantages are to make things a little easier for the user and take some small load off of the server.


Thanks. Do you know why my radio button won't echo out? I have also tried my comments?
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2484
  • View blog
  • Posts: 8,517
  • Joined: 08-August 08

Re: Why won't my radio button display?

Posted 08 April 2012 - 12:58 PM

It only gets posted if you select one, and that works for me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1