Jump to content

Creation of interactive story


Bismark12

Recommended Posts

Hello,I'm new to this forum and to PHP.I would be grateful to any help solving my error:

I want to create

A- html form (solution_a_html.html) with 13 text entry boxes

1=verb,2=room in a house, 3=adjective, 4=noun, 5=room in a house, 6=noun,7=roum in a house, 8=verb, 9=noun, 10=piece of furniture, 11=liquid, 12=number, 13=noun

 

B-plug entered parameters into this paragraph and print out on the screen.(solution_a_php.php)

I need to substitute bracketed text (<text1>) with text box inputs.

The paragraph is

One day while I was <text1> in the <text2> a <text3> <text4> fell through the roof.

It immediately jumped on the <text5> and knocked over the <text6>. Then it

ran out the door into the <text7> and <text8> a <text9> off the <text10>.

It then knocked a glass of <text11> off the coffee table. After <text12> minutes of

chasing the <text4> through the house I finally caught it and put it outside. It

quickly climbed the nearest <text13>.

 

 

My solution

 

solution_a_html.html

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        "http://www.w3.org/TR/html4/loose.dtd">

 

<html lang="en">

 

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Create your own story</title>

 

</head>

 

<body>

Fill in each of the text boxes with the corresponding type of word.

 

If you do not know what one of the words are (such as a verb, or adjective)

click on the word type to launch a new

window and search Google for an explanation.

 

<form method="post" action="solution_a_php.php">

 

<table border=1 cellpadding=0>

 

<tr>

 

<td><b><a href='http://www.google.com/search?q=define:verb' target=_new>Verb</a>:</b>

 

<td><input type="text" name="verb1" size=45></td>

 

</tr><tr>

 

<td><b>Room in a House:</b></td>

 

<td><input type="text" name="room1" size=45></td>

 

</tr><tr>

 

<td><a href='http://www.google.com/search?q=define:adjective' target=_new><b>Adjective:</a></b>

</td>

 

<td><input type="text" name="adjective1" size=45></td>

</tr><tr>

 

<td><a href='http://www.google.com/search?q=define:noun' target=_new><b>Noun:</b></a></td>

 

<td><input type="text" name="noun1" size=45></td>

</tr>

<tr>

 

<td><b>Piece of Furniture:</b></td>

<td><input type="text" name="furniture1" size=45>

</td>

</tr>

<tr>

 

<td><a href='http://www.google.com/search?q=define:noun' target=_new><b>Noun:</b></a></td>

 

<td><input type="text" name="noun2" size=45></td>

</tr>

<tr>

<td><b>Room in a House:</b></td>

 

<td><input type="text" name="room2" size=45></td>

</tr>

<tr>

<td><a href='http://www.google.com/search?q=define:verb' target=_new><b>Verb:</b></a></td>

 

<td><input type="text" name="verb2" size=45></td>

</tr>

<tr>

<td><a href='http://www.google.com/search?q=define:noun' target=_new><b>Noun:</b></a></td>

 

<td><input type="text" name="noun3" size=45></td>

</tr>

<tr>

<td><b>Piece of Furniture:</b></td>

 

<td><input type="text" name="furniture2" size=45></td>

</tr>

<tr>

<td><b>A Liquid:</b></td>

 

<td><input type="text" name="liquid1" size=45></td>

</tr>

<tr>

<td><b>Number:</b></td>

 

<td><input type="text" name="number1" size=45></td>

</tr>

<tr>

<td><a href='http://www.google.com/search?q=define:noun' target=_new><b>Noun:</b></a></td>

<td><input type="text" name="noun4" size=45></td>

</tr><tr>

<td colspan=2><input type="submit" value="Create Story">

</td>

</tr>

 

</table>

 

</form>

 

</body>

 

</html>

 

solution_a_php.php

 

<head>

<title>Create your own story</title>

</head>

 

<body>

<?php

//$_POST Contains information from POST requests (another type of form submission). These values should be checked before use.

 

echo "One day while I was $_POST["verb1"] in the $_POST["room1"] a $_POST[adjective] $_POST["noun1"] fell through the roof.

It immediately jumped on the $_POST["furniture1"] and knocked over the $_POST["noun2"]. Then it

ran out the door into the $_POST["room2"] and $_POST["verb2"] a $_POST["noun3"] off the $_POST["furniture2"].

It then knocked a glass of $_POST[liquid1] off the coffee table. After $_POST["number1"] minutes of

chasing the $_POST["noun1"] through the house I finally caught it and put it outside. It

quickly climbed the nearest $_POST["noun4"].";

 

?>

</body>

</html>

 

Using wampServer 2.0,the browser showed me the text without all the parameters.Also appears notices with undefined index:each parameter example noun1.Where is the error?

Link to comment
https://forums.phpfreaks.com/topic/156073-creation-of-interactive-story/
Share on other sites

Regarding this:

echo "One day while I was $_POST["verb1"] in the $_POST["room1"] a $_POST[adjective] $_POST["noun1"] fell through the roof.
It immediately jumped on the $_POST["furniture1"] and knocked over the $_POST["noun2"]. Then it
ran out the door into the $_POST["room2"] and $_POST["verb2"] a $_POST["noun3"] off the $_POST["furniture2"].
It then knocked a glass of $_POST[liquid1] off the coffee table. After $_POST["number1"] minutes of
chasing the $_POST["noun1"] through the house I finally caught it and put it outside. It
quickly climbed the nearest $_POST["noun4"].";

 

you need to put array values in {}

 

echo "One day while I was {$_POST["verb1"]} in the {$_POST["room1"]} a {$_POST[adjective]} {$_POST["noun1"]} ...

Thanks MCHL ,I tried with your suggestion ,I still have the parameters missing in the outcome.

Look at this :

 

<?php


print "One day while I was {$_POST["verb1"]} in the {$_POST["room1"]} a {$_POST["adjective1"]} 
{$_POST["noun1"]}
fell through the roof. It immediately jumped on the {$_POST["furniture1"]} and 
knocked over the {$_POST["noun2"]}. 
Then it ran out the door into the {$_POST["room2"]} and 
{$_POST["verb2"]} a {$_POST["noun3"]} off the {$_POST["furniture2"]}.
It then knocked a glass of 
{$_POST["liquid1"]} off the coffee table. 
After {$_POST["number1"]} minutes of chasing the 
{$_POST["noun1"]} through the house I finally caught it and put it
outside. 
It quickly climbed the nearest {$_POST["noun4"]}.";

?> 

 

 

 

 

The browser output is:

 

One day while I was in the a fell through the roof. It immediately jumped on the and knocked over the . Then it ran out the door into the and a off the . It then knocked a glass of off the coffee table. After minutes of chasing the through the house I finally caught it and put it outside. It quickly climbed the nearest . 

 

Any idea why?

 

 

what data are you typing in the text inputs when you fill out the form?

 

I don't see anything wrong with your code (now that you've included the curly braces).  Try echoing the form values by themselves first on solution_a_php.php to see if the problem is the values themselves (e.g. does $_POST['verb1'] print nothing by itself?) or if the problem is the string you're injecting them into.  (e.g. echo $_POST['verb1'] produces the correct value, but echo "One day while I was {$_POST["verb1"]}" does not).  That should help narrow the problem down.

Tks AmandaF.Actually I went to Zend Studio IDE and opening my solution_a_html.html file to the browser showed me my Form that I filled with verb,noun,adjective,etc... when I click the submit button (create story) on IE it doesn't open.How it work? by clicking the create story button it send all the info typed to solution_a_php.php and after when I ran the php file I saw

the text without the parameters  and "undifined index : noun1,adjective1,room1,etc..."

thanks for suggestions...

 

Bismark12

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.