Jump to content

Recommended Posts

Hey guys i am trying to get an html form to post to php to tell a story basically to test what i know but apparently......... it does not work 

the html  is rather long now so i only posting a little.

<html>

<head>

<title>Story</title>

</head>

<body>

<h1>Story</h1>

<h3>Please fill in the blanks below, and I'll tell

    you a story</h3>

<form method = "post"

      action = "story.php">

<table border = 1>

<tr>

  <th>Color:</th>

  <th>

    <input type = "text"

          name = "color"

          value = "">

  </th>

</tr>

<tr>

  <th>Musical Instrument</th>

  <th>

    <input type = "text"

          name = "instrument"

          value = "">

  </th>

</tr>

 

and the php is

 

<?php

 

print <<<HERE

<h3>

Little Boy $color, come blow your $instrument!<br>

The $anim1's in the $place, the $anim2's in the $vegetable.<br>

Where's the boy that looks after the $anim3?<br>

He's under the $structure, $action.

</h3>

HERE;

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/65150-solved-html-post-to-php/
Share on other sites

None of the variables you use in story.php are defined anywhere. This is a result of the register_globals setting being off (a good thing) which has been the default in php for a long time now for security reasons. Use....

 

<?php

print <<<HERE
<h3>
Little Boy {$_POST['color']}, come blow your {$_POST['instrument']}!

The {$_POST['anim1']}'s in the {$_POST['place']}, the {$_POST['anim2']}'s in the {$_POST['vegetable']}.

Where's the boy that looks after the {$_POST['anim3']}?

He's under the {$_POST['structure']}, {$_POST['action']}.
</h3>
HERE;

?>

 

instead.

in your html you have

<tr>
  <th>Color:</th>
  <th>
    <input type = "text"
           name = "color"
           value = "">
  </th>
</tr>

 

now the

name = "color"

 

is pulled into the php via $_POST['color'] not $color

 

you could do

 

$color  = $_POST['color'];

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.