echo“<p>”。 $ value。 “</ P>”;

Ok my first time asking question here. This as been very helpful in the past but now i'm lost. I'm trying to understand how php work with the help of a book. So i did the exercise as it was shown in the book and the result if not what it should be.

Here's the code:

<div id="content">
    <p>Here's a record of everything in the REQUEST array:</p>
    <?php
    foreach($_REQUEST as $value) {
        echo "<p>" . $value . "</p>";
        }
        ?>
    </div>
    <div id="footer"></div>
</body>

And here's the result:

Here's a record of everything in the REQUEST array:

" . $value . "
"; } ?>

Why is not showing the info it is suppose to? Thanks.


Ok here's all the code:

showRequestInfo.php

<!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"> <head> <meta
> http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link
> href="/wamp/www/livrephp/css/phpMM.css" type="text/css"
> rel="stylesheet" />
> 
> <title>Untitled Document</title> </head>
> 
> <body>    <div id="header"><h1>PHP & MySQL: The Missing
> manual</h1></div>
>     <div id="example">Example 3-2</div>
>     
>     <div id="content">
>       <p>Here's a record of everything in the REQUEST array:</p>
>         <?php         foreach($_REQUEST as $value) {          echo "<p>" . $value . "</p>";           }           ?>
>             
>           
>         </div>
>         <div id="footer"></div> </body> </html>

And this goes with this file called "socialEntryForm.php"

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/wamp/www/livrephp/css/phpMM.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>

<body>
    <div id="header"><h1>PHP & MySQL: The misiing manual</h1></div>
    <div id="example">Example -1</div>

    <div id="content">
        <h1>Join the missing manual (Digital) Social Club</h1>
        <p>Please enter your online connections below:</p>
        <form action="../showRequestInfo.php" method="post">
            <fieldset>
            <label for="first_name">First Name:</label>
            <input type="text" name="first_name" size="20" /><br />
            <label for="last_name">Last Name:</label>
            <input type="text" name="last_name" size="20" /><br />
            <label for="email">Email Address:</label>
            <input type="text" name="email" size="50" /><br />
            <label for="facebook_url">Facebook URL:</label>
            <input type="text" name="facebook_url" size="50" /><br />
            <label for="twitter_handle">Twitter Handle:</label>
            <input type="text" name="twitter_handle" size="50" /><br />
            </fieldset>
            <br />
            <fieldset class="center">
                <input type="submit" value="Join The Club" />
                <input type="reset" value="Clear and Restart" />
            </fieldset>
          </form>
     </div>

     <div id="footer"></div>
</body>
</html>

Are you sure your file is a PHP file and it's being run on a PHP enabled server? The browser seems to be receiving the code unparsed, thinking that there's a tag starting at <?php and ending at the first <p> tag. If you look at the source, you'll probably see your PHP code, untouched by the server.

In other words: Your code is correct and the problem is your file type or server configuration. If you are indeed using a server on your machine, make sure you're running the file right, e.g. if it's in the root, open http://localhost/your_file.php, and not C:\xampp\htdocs\your_file.php.

EDIT: Just for the heck of it, I replicated your issue with a fiddle. I got the exact same output as you, meaning it's not getting parsed by the server. Who said JSFiddle was only good for JavaScript?

$_REQUEST Contains data which is gathered from cookies, $_POST and $_GET .. Are you sure that your data is properly assigned?

Take this example.

print_r($_REQUEST); just doing that without no <form method="get/post"> will produce a blank array, that might be why you are getting nothing

Your snippet is correct.. you are lacking a html form to go with that..

Example:

<form method="POST">
<input type="submit" name="test" value="ThisIsCorrect">
</form>

With your code you have shown your question.. your $_REQUEST array will return the value of the button. In this case "ThisIsCorrect"


Moral Of this?

Ensure that you are using using post/get/cookies before calling the $_REQUEST, and for future reference, just using $_POST & $_GET is cleaner to use.. But that is down to my personal preference.


How is the $_REQUEST Array constructed?

Consider this:

the array will contain the name as the array key and the value as the value..

So taking this into account:

<form method="POST">
<input type="text" name="username">
<input type="submit" name="test" value="ThisIsCorrect">
</form>

For your text box & Submit button the array will be:

array ("username" => "UserInputData", "test" => "ThisIsCorrect");