Jump to content

I need help with my php code!!plzz


boyyo

Recommended Posts

i just started a book called head first php and mysql and i think the syntax in the book is wrong this is what i put:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Aliens Abducted Me - Report an Abduction</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</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 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Your email address is ' . $email;  
?>
</body>
</html>

 

I saved it as an html as the book says and this is what comes out:

 

Aliens Abducted Me - Report an Abduction

 

'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . '
'; echo 'Describe them: ' . $alien_description . '
'; echo 'Was Fang there? ' . $fang_spotted . '
'; echo 'Your email address is ' . $email; ?>

 

Is there a reason that it is putting that?Isnt it supposed to put out a form?Help Please!

Link to comment
Share on other sites

I enjoyed that book! Poor fang. As for the book I went over every subject in the book and found no issues. You can also head over to their main website and download the code found in the book here:

 

http://www.headfirstlabs.com/books/hfphp/

 

And dcro2 gave the correct answer you're missing the form, and everything after <?php up until ?> goes into a file with the extension .php

 

Link to comment
Share on other sites

Ohhh!! So that code at the beggining:

 

 

<label for="firstname">First name:</label>

    <input type="text" id="firstname" name="firstname" /><br />

    <label for="lastname">Last name:</label>

    <input type="text" id="lastname" name="lastname" /><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="whenithappened" name="whenithappened" /><br />

    <label for="howlong">How long were you gone?</label>

    <input type="text" id="howlong" name="howlong" /><br />

    <label for="howmany">How many did you see?</label>

    <input type="text" id="howmany" name="howmany" /><br />

    <label for="aliendescription">Describe them:</label>

    <input type="text" id="aliendescription" name="aliendescription" size="32" /><br />

    <label for="whattheydid">What did they do to you?</label>

    <input type="text" id="whattheydid" name="whattheydid" size="32" /><br />

    <label for="fangspotted">Have you seen my dog Fang?</label>

    Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" />

    No <input id="fangspotted" name="fangspotted" 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>

 

 

is the form. I thought you had to delete that and input the code that it says on the book and that would be the form! Ohhh wow im so dumb haha thanks for the help! I really appreciate it!

Link to comment
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.