I am not able to get the expected results.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smartguy1616
Forum Newbie
Posts: 8
Joined: Mon Mar 29, 2010 3:18 pm

I am not able to get the expected results.

Post by smartguy1616 »

I am not able to get the expected results. Can anyone tell me why?

Below is a simple HTML code.

Code: Select all

<html>
<body>
<p>Share your story of alien abduction:</p>
<form method="post" action="report.php">
<label for="firstname">First name:</label>
<input type="text" id="first_name" name="first_name" /><br />
<label for="lastname">Last name:</label>
<input type="text" id="last_name" name="last_name" /><br />
<label for="email">What is your email address?</label>
<input type="text" id="email" name="email" /><br />
<label for="whenithappened">When did it happen?</label>
<input type="text" id="when_it_happened" name="when_it_happened" /><br />
<label for="howlong">How long were you gone?</label>
<input type="text" id="how_long" name="how_long" /><br />
<label for="howmany">How many did you see?</label>
<input type="text" id="how_many" name="how_many" /><br />
<label for="aliendescription">Describe them:</label>
<input type="text" id="alien_description" name="alien_description" size="32" /><br />
<label for="whattheydid">What did they do to you?</label>
<input type="text" id="what_they_did" name="what_they_did" size="32" /><br />
<label for="fangspotted">Have you seen my dog Fang?</label>
Yes <input id="fang_spotted" name="fang_spotted" type="radio" value="yes" />
No <input id="fang_spotted" name="fang_spotted" type="radio" value="no" /><br />
<img src="fang.jpg" width="100" height="175"
alt="My abducted dog Fang." /><br />
<label for="other">Anything else you want to add?</label>
<textarea id="other" name="other"></textarea><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
</body>
</html>

Below is the PHP code which is called on submittion.

<html>
<head>
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>
<?php
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$alien_description = $_POST['description'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
echo 'Hello Mr.' . $first_name . ' ' . $last_name . 'Thanks for submitting the form.<br />';
echo 'You say that you were abducted on ' . $when_it_happened . '<br />';
echo 'and were gone for ' . $how_long . '<br />';
echo 'There were ' . $how_many . 'aliens who looked like ' . $alien_description . '<br />';
echo 'who tried to ' . $what_they_did . 'you';
echo 'Was Fang there?' . $fang_spotted . '<br />';
echo 'You also say that:' . $other . '<br />';
echo 'Your email address is: ' . $email;
?>
</html>
I am filling in all the information but most of them are not being shown. Can you please let me know the reason and solution?

First name: Saumya
Last name: Purkayastha
What is your email address? smartguy1616@yahoo.co.in
When did it happen? Tuesday
How long were you gone? 3 days
How many did you see? 5
Describe them: ugly and horrible
What did they do to you? kiss and hug
Have you seen my dog Fang? No
Anything else you want to add? It was a mixed experience.

Ideally the result on submitting should be as below as I am expecting:-
Aliens Abducted Me - Report an Abduction
Hello Mr. Saumya Purkayastha. Thanks for submitting the form.
You say that you were abducted on Tuesday
and were gone for 3 days
There were 5 aliens who looked like ugly and horrible
who tried to kiss and hug you.
Was Fang there? no
You also say that: It was a mixed experience.
Your email address is: smartguy1616@yahoo.co.in

Aliens Abducted Me - Report an Abduction
Hello Mr. Thanks for submitting the form.
You say that you were abducted on
and were gone for
There were aliens who looked like
who tried to you.
Was Fang there?
You also say that:
Your email address is: smartguy1616@yahoo.co.in

Please let me know how to get the expected results. What modifications do I have to do in the code?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: I am not able to get the expected results.

Post by Christopher »

You are not getting all the values from the $_POST array. Also, for security see this page in the PHP manual:

http://us.php.net/manual/en/faq.html.php
(#10850)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: I am not able to get the expected results.

Post by AbraCadaver »

Just like the five variables that are working, you have to do this for all of the variables that you are displaying:

Code: Select all

$first_name = $_POST['first_name'];
//etc...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
smartguy1616
Forum Newbie
Posts: 8
Joined: Mon Mar 29, 2010 3:18 pm

Re: I am not able to get the expected results.

Post by smartguy1616 »

Oh thanks, I did not know I am so dumb. I should have noticed that. How did I not? By the way this was my first handwritten program in php.
Post Reply