Tuesday, February 7, 2012

PHP and HTML programming?

Ok i created a html file:



%26lt;html%26gt;

%26lt;head%26gt;

%26lt;title%26gt;html form%26lt;/title%26gt;

%26lt;/head%26gt;

%26lt;body bgcolor=yellow%26gt;

%26lt;hr /%26gt;

%26lt;form action="myphp.php" method="GET"%26gt;

%26lt;b%26gt;Type your name here: %26lt;/b%26gt;

%26lt;input type="text" name="namestring" size=50%26gt;

%26lt;p/%26gt;%26lt;b%26gt;Talk about yourself here: %26lt;/b%26gt;


%26lt;textarea name="comments" rows=5

cols=50%26gt;i was born... %26lt;/textarea%26gt;

%26lt;p/%26gt;%26lt;b%26gt; Choose your food: %26lt;/b%26gt;

%26lt;input type="radio" name="choice" value="burger"/%26gt;Hamburger

%26lt;input type="radio" name="choice" value="fish" /%26gt;Fish

%26lt;input type="radio" name="choice" value="steak" /%26gt;Steak

%26lt;input type="radio" name="choice" value="yogurt" /%26gt;Yogurt

%26lt;p /%26gt; %26lt;b%26gt;Choose a work place:%26lt;/b%26gt;


%26lt;input type="checkbox" name="place1" value="LA"/%26gt;Los Angeles




%26lt;input type="checkbox" name="place2" value="SJ" /%26gt;San Jose




%26lt;input type="checkbox" name="place3" value="SF" Checked%26gt;San Francisco

%26lt;p/%26gt;

%26lt;b%26gt;Choose a vacation spot: %26lt;/b%26gt;

%26lt;select name="location"%26gt; %26lt;option selected value="hawaii"

/%26gt; Hawaii

%26lt;option value="bali" /%26gt;Bali

%26lt;option value="maine" /%26gt;Maine

%26lt;option value="paris" /%26gt;Paris

%26lt;/select%26gt;

%26lt;p/%26gt;

%26lt;input type="submit" value="Submit"%26gt;

%26lt;/p%26gt;

%26lt;input type="reset" value="Clear"%26gt;

%26lt;/form%26gt;

%26lt;hr /%26gt;

%26lt;/body%26gt;

%26lt;/html%26gt;



And i want to write a PHP file that will take the user input and display what they selected or typed in.



heres what i got so far:

%26lt;html%26gt;%26lt;head%26gt;%26lt;title%26gt;php%26lt;/title%26gt;%26lt;/head%26gt;

%26lt;body%26gt;

%26lt;?php

extract($_REQUEST);



?%26gt;

%26lt;/body%26gt;

%26lt;/html%26gt;PHP and HTML programming?
%26lt;?php

// Fetch the form-submitted values. $_GET because our sending method was 'get'. If it were post, we would use $_POST



$YourName=$_GET['namestring'];

$AboutYou=$_GET['comments'];

$Food=$_GET['choice'];

$Workplace=$_GET['place1'].", ".$_GET['place2'].", ".$_GET['place3'];

$VacationSpot=$_GET['location'];



// Print our variables on to the screen



echo "Your name: ".$YourName."%26lt;br/%26gt;

About you: ".$AboutYou."%26lt;br/%26gt;

Food: ".$Food."%26lt;br/%26gt;

Workplace: ".$Workplace."%26lt;br/%26gt;

Vacation spot: ".$VacationSpot."%26lt;br/%26gt;";

?%26gt;PHP and HTML programming?
%26lt;?php



$name = $_GET["namestring"];

$comments = $_GET["comments"];

$choice = $_GET["choice"]; //you've gotta rework your radio buttons as they all have the same name!!!!

//etc, you get the idea

?%26gt;



//now to display them

//html here

your name is: %26lt;?php echo $name; ?%26gt;

your comments are: %26lt;?php echo $comments; ?%26gt;

//you can also use get directly here

your place is: %26lt;?php echo $_GET["place1"]; ?%26gt;

No comments:

Post a Comment