Page 1 of 1

NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 19:25
by mustanggirl
I just installed XAMPP and am new to PHP, APACHE etc. I was able to pull up the sample php docs with no problem and can view my html doc with no problem. When I try to pull up my document that is saved as .php, but hast html embedded, I get the following error:

Parse error: parse error in C:\xampp\htdocs\popcorn3.php on line 1

This error occurs even if I delete the existing line 1. I am using an example straight from my text book, so just not sure if I have a setup problem or what?

PLEASE HELP! I have been trying to get this to work for days!
ThX.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 19:34
by Wiedmann
Parse error: parse error in C:\xampp\htdocs\popcorn3.php on line 1

if I have a setup problem or what?

There is an error in your code.

(Nothing more to say without a sample code.)

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 19:56
by mustanggirl
Is the error on line1 or just somewhere in my document? Because like I said before if I just delete the line 1 that is there now, it will give the error for the new line 1.

It is a long program, so quite possible an error somewhere if that is the way it works.

Existing doc starts like this...there are other instances of php code in the document as well.
Code: Select all
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN"
"http://www.w3.org/RT/xhtml11/DTD/xhtml11.dtd">

<!--popcorn3.php - Processes the form described in
   popcorn3.html
   -->
<html xmlns = "http://www.w3.org/1999/xhtml">
   <head>
      <title> Process the popcorn3.html form </title>
   </head>
   <body>
      <?php
   // Get form data values
      $unpop = $_POST["unpop"];
      $caramel = $_POST["caramel"];
      $carmelnut = $_POST["caramelnut"];
      $toffeynut = $_POST["toffeynut"];
      $name = $_POST["name"];
      $street = $_POST["street"];
      $city = $_POST["city"];
      $payment = $_POST["payment"];
      
   // If any of the quantities are blank, set them to zero
      if ($unpop == " ") $unpop = 0;
      if ($caramel == " ") $caramel = 0;
      if ($caramelnut == " ") $caramelnut = 0;
      if ($toffeynut == " ") $toffeynut = 0;
      
   // Compute the item costs and total cost
      $unpop_cost = 3.0 * $unpop;
      $caramel_cost = 3.5 * $caramel;
      $caramelnut_cost = 4.5 * $caramelnut;
      $toffeynut_cost = 5.0 * $toffeynut;
      $total_price = $unpop_cost + $caramel_cost +
                $caramelnut_cost + $toffeynut_cost;
      $total_items = $unpop + $caramel + $caramelnut + $toffeynut;
      
   // Return the results to the browser in a table
       ?>

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 20:08
by Wiedmann
if I just delete the line 1 that is there now, it will give the error for the new line 1.

Sure?

The current line 1 is indeed a problem. But without this line there is no syntax error in your sample code.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 20:20
by mustanggirl
OK, I am getting the exact same error on this .PHP file which is pretty short and I can post the whole thing here.
Code: Select all
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!--powers.php - An example to illustrate several of the
   sorting functions  -->
   
<xml xmlns = "http//www/w3.org/1999/xhtml">
   <head><title>Sorting</title>
</head>
<body>
   <?php
      $original = array("Fred" => 31, "Al" => 27,
         "Gandalf" => "wizard",
         "Betty" => 42, "Frodo" => "hobbit");
   ?>
   <h4> Original Array </h4>
   <?php
      foreach ($original as $key => $value)
      print("[$key] => $value <br />");
      
      $new = $original;
      sort($new);
      ?>
      
      
</body>
</html>


so is it possible that if I get the parsing error and you don't that there is some set up problem?

BTW thanks for helping.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 20:44
by Wiedmann
OK, I am getting the exact same error on this .PHP file which is pretty short and I can post the whole thing here.

Correct. Because you have the same 1st line as in your last script. If you remove this line, you have no PHP error.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 22:35
by mustanggirl
ok, as per your advice I took out the first line. So now my code looks like this....

<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!--powers.php - An example to illustrate several of the
sorting functions -->

<xml xmlns = "http//www/w3.org/1999/xhtml">
<head><title>Sorting</title>
</head>
<body>
<?php
$original = array("Fred" => 31, "Al" => 27,
"Gandalf" => "wizard",
"Betty" => 42, "Frodo" => "hobbit");
?>
<h4> Original Array </h4>
<?php
foreach ($original as $key => $value)
print("[$key] => $value <br />");

$new = $original;
sort($new);
?>


</body>
</html>


when I pull up the document I now get a blank page....so new problem?

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 23:03
by mustanggirl
OK so I tried this again, took out the first line...now I CAN see the information from the .php document. I can also still see the information in the .html file...however they are not talking to each other properly. When I pull up the .html file and input information, the .php file should then be read and do some calculations and re-display the table. However when I put in information into the table from the html file and hit submit, I can tell that it is looking for the php document and it then displays the error Internet Explorer cannot display the webpage. I have the .php and the .html file saved in the c:/xampp/htdocs file. Perhaps the problem is in the form action call, but I put the path of the .php file there.

this is what it says at the top of the windows exporer error page.

http://c/xampp/htdocs/popcorn3.php


I do really appreciate your help...or anyones!

I wish I could attach files here to show you.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 23:17
by Wiedmann
Perhaps the problem is in the form action call, but I put the path of the .php file there.

If both files are in the same directory, only use the filename in the action attribute.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 23:30
by mustanggirl
Did as you suggested. Now nothing happens when I hit the submit button. When I hover over it I can see that it is pointed to the path of the document.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 07. May 2009 23:54
by Wiedmann
Now nothing happens when I hit the submit button.

The address bar in your browser doesn't change?

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 08. May 2009 00:34
by mustanggirl
nope.

Re: NEWBIE needs help! Getting parsing error on line 1

PostPosted: 08. May 2009 00:37
by mustanggirl
WOOHOO! Looks like I didn't refresh the browser with the new version of the .html. It is working!

You have been a real help! Hopefully I won't need anymore! Only 2 more weeks left in this class!

Thank you so very much.