Jump to content

Recommended Posts

I'm having to create a simple madlib game in php but whenever I open the html document but whenever I submit it on the html site it doesn't print it right.

 

html code

<html>
<body>
<h1> My MadLib Lab </h1>
<form action="madlib.php" method="REQUEST">
Enter a Noun: <input type="text" name="noun1" ><br />
Enter an Adjective: <input type="text" name="adj1" ><br />
<input type="submit" value="Click to see your MadLib" >
</form>
</body>
</html>

 

 

php code

<html>

<body>
<?php
$noun1 = $_REQUEST['noun1'];
$adj1 = $_REQUEST['adj1'];

print <h1>"The $adj1 old $noun1"</h1>;

print <br>"There once was an $adj1 $noun1, who lived in a van down by the river."</br>;
print <br>"<The end."</br>;


?>
</html>s ou
</body>

 

 

This is what it prints out

"The $adj1 old $noun1";

There once was an $adj1 $noun1, who lived in a van down by the river.;

print "The end."; ?>

 

Any help would be appreciated.

 

Thanks,

David

Link to comment
https://forums.phpfreaks.com/topic/281907-simple-madlib-help/
Share on other sites

Are you running these pages on a web server or are you opening them up directly on your PC? PHP files must be requested from a web server that has PHP enabled so it can execute the PHP code and send the output to the browser. You can set up a webserver on your machine if you want using something like XAMPP or WAMP. but, I bet if you look at the source code of the page you will see that ALL of the code from madlib.php is there. You just can't see the PHP code in the display because the HTML considers the PHP opening/closing tags as HTML tags and hides it.

Link to comment
https://forums.phpfreaks.com/topic/281907-simple-madlib-help/#findComment-1448406
Share on other sites

You need to access them via apache using a URL, not by just opening them directly in the browser (with file->open for example). Open your browser then go to the URL http://localhost/madlib.php and it should work, assuming you have saved your madlib.php file into the document root folder that xampp sets up.

Link to comment
https://forums.phpfreaks.com/topic/281907-simple-madlib-help/#findComment-1448408
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.