PHP/HTML help. Mad Lib Errors

I’m fairly new to PHP so please don’t be too mean lol. I’m getting some errors and I’m not sure what I’m doing wrong. Please just point me in a direction!
I need to create a MadLibs with textbox, checkbox, and dropdown. When submitted, it should tell the story with the words from the form in a different color.
Thank you!

HTML

Crazy Mad Lib body { background: #dad1ff; text-align: center; } h2 { color: #68197f; }

Create your crazy story here by filling in the blanks!

Please fill out the form below on your favorite vacation get away! A males name
A breed of dog
Please pick a verb: Skipping Running Roller blading
Name an animal
Please pick a color Blue Purple Red
Please provide a verb
Please pick an object: Rock Bridge
Please pick an emotion: Happy Sad Mad Relieved

PHP

Crazy Mad Lib body { background: #dad1ff; text-align: center; }

h2 {
color: #68197f;
}

#randomwords {
color: #7001ff;
}

Heres the crazy story that you created!

<?php $males_name = $_POST['firstname']; $breed = $_POST['breed']; $male_verb = $_POST['maleverb']; $animal = $_POST['animal']; $color = $_POST['color']; $animal_verb = $_POST['animalverb']; $hiding = $_POST['hiding']; $emotion = $_POST['emotion'];

echo 'Once upon a time, there was a young man named ’ . $males_name . ’ This man and his ’ . $breed . ’ named Pudge decided to go out for the day.
’ . $males_name . ’ and Pudge were ’ . $male_verb . ’ when all of a sudden something came out from behind a tree! It was a ’ . $animal . '. When Pudge started
barking at it, the ’ . $animal . ’ turned from yellow to ’ . $color . ’ because it was angry! It started to ’ . $animal_verb . ’ after the two friends!
After ten minutes of dodging the animals claws, the two friends were finally able to hide under a ’ . $hiding . '! Pudge and ’ . $males_name . ’ were feeling
’ . $emotion . ’ because of the attack. After collecting themselves, the two friends decided it was best to continue on with their day!
?>

Again…I’m sorry if I’m bad at this!!

You have an error on line 92. You are missing a quote and semi-colon at the end of:

continue on with their day![size=14pt]’;[/size]?>

It is really easy to get lost in all that escaping. There is an easier way.

Rather than create a bunch of new variables like below, use the ones you already have. Instead of doing like below:
[php]$males_name = $_POST[‘firstname’];[/php]

You can use your POST variables like below and not have to do all that escaping:
[php]
echo “Once upon a time, there was a young man named {$_POST[‘firstname’]} This man and his {$_POST[‘breed’]} named Pudge decided to go out for the day.
{$_POST[‘males_name’]} and Pudge were”;
[/php]

** NOTICE THE OPENING AND CLOSING DOUBLE QUOTES **

If your going to create variables from the POST data all you have to do is use opening and closing double quotes on your echo and then you wont have to escape the text for your variables to work

Do this:

[php]
echo “Once upon a time, there was a young man named $males_name This man and his $breed named Pudge decided to go out for the day.
$males_name and Pudge were $male_verb when all of a sudden something came out from behind a tree! It was a $animal . When Pudge started”;
[/php]

Keyword to learn: Variable Interpolation

Simple Example:
[php]$foo=‘Hello World’;
echo ‘$foo’;//Result is $foo
echo “$foo”;//Result is Hello World[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service