Jump to content

Recommended Posts

Hi Everyone,

 

I am very new to PHP and trying to teach myself some of the basics.  I have an XHTML page that takes some simple input and calls my php script once the submit button is clicked.  I am getting some results, but there appears to be some parsing issues with the last portion of the text.  Here is my very simple PHP script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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>Registration</title>
</head>
<body>
    <h2>Registration Results</h2>
    
    <?php
    
    $okay = TRUE;
    
    if ($okay)
    {
        print'<p>You have been successfully registered (but not really).</p>';
    }
    
    ?>
    
</body>
</html>

 

Here is my output:

 

Registration Results
You have been successfully registered (but not really).'; } ?> 

 

I cannot seem to figure out why I am seeing the additional characters after the period

' ; } ?>

 

Any suggestions?

 

I have PHP version 5.3 installed and I am running this on Apache 2.2.11

 

Thanks for reading this.

Link to comment
https://forums.phpfreaks.com/topic/206652-unexpected-characters-on-output/
Share on other sites

The page is called handle_reg2.php

 

Here is the full page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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>Registration</title>

    <!-- Define a CSS class -->
    <style type="text/css" media="screen">
    .error {color:red;}
    </style>
    
</head>
<body>

    <h2>Registration Results</h2>
    
    <?php
    
    $okay = TRUE;
    
    //validate the email address
    if (empty($_post['email']))
    {
        print '<p class="error">Please enter your email address.</p>';
        $okay = FALSE;
    }
    
    if ($okay)
    {
        echo'You have been successfully registered (but not really).'; //need to change back to print('<p>You have been successfully registered (but not really).</p>';
    }
    
    ?>
    
</body>
</html>

 

I must be missing something really simple...

Yes, that is how the page is being accessed.  Also, i have another XHTML page that sends data to this script via

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

.  When I access the logic by either means I receive the same result.  The extra characters at the end of the string.

I'll go ahead and add both pages so it will make this less confusing.

 

Main page:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Registration Form</title>
</head>
<body>
    <!-- Script 6.1 - register.html -->
    
    <div><p>Please complete this form to register:</p>
        
    <!-- Initial tag form -->
    <form action="handle_reg2.php"
            method="post">
        
        <!-- Inputs for email address and password -->
        <p>Email Address: <input type="text"
            name="email" size="30" /></p>
        <p>Password: <input type="password"
            name="password" size="20" /></p>
        <p>Confirm Password: <input type="password"
            name="confirm" size="20" /></p>
        
        <!-- Inputs for the month of birth -->
        <p>Date Of Birth:
        <select name="month">
            <option value="">Month</option>
            <option value="1">January<option>
            <option value="2">February<option>
            <option value="3">March<option>
            <option value="4">April<option>
            <option value="5">May<option>
            <option value="6">June<option>
            <option value="7">July<option>
            <option value="8">August<option>
            <option value="9">September<option>
            <option value="10">October<option>
            <option value="11">November<option>
            <option value="12">December<option>
        </select>
        
        <!-- Inputs for the day of birth -->
        <select name="day">
            <option value="">Day</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
            <option value="13">13</option>
            <option value="14">14</option>
            <option value="15">15</option>
            <option value="16">16</option>
            <option value="17">17</option>
            <option value="18">18</option>
            <option value="19">19</option>
            <option value="20">20</option>
            <option value="21">21</option>
            <option value="22">22</option>
            <option value="23">23</option>
            <option value="24">24</option>
            <option value="25">25</option>
            <option value="26">26</option>
            <option value="27">27</option>
            <option value="28">28</option>
            <option value="29">29</option>
            <option value="30">30</option>
            <option value="31">31</option>
        </select>
        
        <!-- Input for birth year -->
        <input type="text" name="year"
               value="YYYY" size="4" />
        </p>
        
        <!-- Drop down menu for user's favorite color -->
        <p>Favorite Color:
        <select name="color">
            <option value="">Pick One</option>
            <option value="red">Red</option>
            <option value="yellow">Yellow</option>
            <option value="green">Green</option>
            <option value="blue">Blue</option>
        </select>
        </p>
        
        <!-- Submit button -->
        <input type="submit"
               name="submit"
               value="Register" />
    </form>
    
    </div>
    
</body>
</html>

 

PHP script page [handle_reg2.php]:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Registration</title>
</head>
<body>
    <h2>Registration Results</h2>>
    
    <? php
    
        //Script 6.2 - handle_reg.php
       
       //enable error checking
       ini_set ('display_errors', 1);
       error_reporting(E_ALL | E_STRICT);
       
       //create variable flag
       $okay = TRUE;
       
       //print a message if everything is okay
       if ($okay)
       {
        print '<p>You have been successfully registered (but not really).</p>';
       }
    ?>

</body>
</html>

 

 

As PFMaBiSmAd Said:

All you are seeing is the raw un-parsed php code being output on your page (do a 'view source' in your browser.)

 

Looks like your server doesn't have php installed. Run this to find out:

 

test.php

<?php
$test = true;
if($test != true){ echo('>PHP Not Installed<'); }
?>

 

Basically if PHP isnt being parsed (not installed/not recognized extension/Opening Tag) then HTML will see everything on either side of "php not installed" as an unknown tag, and hide it from view.

 

To do a "View Source":

Go to the page in your browser

-> Click View (at the top)

  -> Click "View Source" or "Page Source"

Copy the contents and paste in a code tag.

 

-cb-

Here are the results from the view source (sorry, forgot to put this up here earlier)

 

<!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/1000/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html"; charset=utf-8"/>
    
    <title>Registration</title>
    
</head>
<body>
    <h2>Registration Results</h2>
    
    <? php
    
        //Script 6.2 - handle_reg.php
       
       //enable error checking
       ini_set ('display_errors', 1);
       error_reporting(E_ALL | E_STRICT);
       
       //create variable flag
       $okay = TRUE;
       
       //print a message if everything is okay
       if ($okay)
       {
        echo '<p>You have been successfully registered (but not really).</p>';
       }
    ?>

</body>
</html>

 

ChemicalBliss the server has PHP installed.  I ran

phpinfo()

without issue and was directed to the appropriate page.

_SERVER["SERVER_SOFTWARE"]	Apache/2.2.11 (Win32) PHP/5.3.0

 

I hope this helps.

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.