Kaworu
Active Coder
My problem
Hello!
I am learning how to code in PHP. I created a simple page that is simulating a car parts store. I encountered some error after opening a file and checking if it is working. What surprises me most is the fact, that PHP is telling me of some kind of “unexpected end of file error” that is happening after the </html> ending tag.
[In fact I do not know if opening a file is a problem in this case or just if/else statement. It’s hard to tell, to be honest.]
It’s a really simple code, yet it is not working at all. And I do not know what I did wrong. If some of you could help me out, I would be grateful.
Explanation of the code
Okay, so I have a html page when you can tell how many tires/car oil etc you want to buy. This form links to a php script that should open orders.txt file. If it cannot be opened, there should be some kind of explanation to the user (if statement). If it can be opened, the user should also get a confirmation.
My bug
The error message is as follows:
Line 36 is a line after </html> closing tag and well after ?> tag.
Source code
Hello!
I am learning how to code in PHP. I created a simple page that is simulating a car parts store. I encountered some error after opening a file and checking if it is working. What surprises me most is the fact, that PHP is telling me of some kind of “unexpected end of file error” that is happening after the </html> ending tag.
[In fact I do not know if opening a file is a problem in this case or just if/else statement. It’s hard to tell, to be honest.]
It’s a really simple code, yet it is not working at all. And I do not know what I did wrong. If some of you could help me out, I would be grateful.
Explanation of the code
Okay, so I have a html page when you can tell how many tires/car oil etc you want to buy. This form links to a php script that should open orders.txt file. If it cannot be opened, there should be some kind of explanation to the user (if statement). If it can be opened, the user should also get a confirmation.
My bug
The error message is as follows:
[B] Parse error[/B]: syntax error, unexpected end of file in [B]D:\xampp\htdocs\scripts\Ch1\place_an_order_v2.php[/B] on line [B]36 [/B]
Line 36 is a line after </html> closing tag and well after ?> tag.
Source code
[CODE lang="php" title="place_an_order_v2.php"]
<!DOCTYPE html>
<?php
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title> Car parts - an order </title>
</head>
<body>
<h1>Car parts</h1>
<h2>Sent order</h2>
<?php
$wp = fopen("$document_root./orders - OK/orders.txt", "ab");
if($wp == false):
{
echo "<p><b>We are sorry, we cannot take your order right now.
Please, try again later.</b></p>";
exit;
}
else:
{
echo "<p><b>We did take your order. Thank you for your business.</b></p>";
}
?>
</body>
</html>
[/CODE]
<!DOCTYPE html>
<?php
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title> Car parts - an order </title>
</head>
<body>
<h1>Car parts</h1>
<h2>Sent order</h2>
<?php
$wp = fopen("$document_root./orders - OK/orders.txt", "ab");
if($wp == false):
{
echo "<p><b>We are sorry, we cannot take your order right now.
Please, try again later.</b></p>";
exit;
}
else:
{
echo "<p><b>We did take your order. Thank you for your business.</b></p>";
}
?>
</body>
</html>
[/CODE]
[CODE lang="html" title="HTML code linking to PHP code (in case you need it)"]<form action = "place_an_order_v2.php" method= "post">
<table style = "border: 0px;">
<tr style = "background: #cccccc;">
<td style = "width: 150px; text:align: center;"> Product </td>
<td style = "width: 15px; text-align: center;"> Quantity </td>
</tr>
<tr>
<td> Tires </td>
<td><input type="text" name="number_of_tires" size ="3" maxlength="3" /></td>
</tr>
<tr>
<td> Car oil </td>
<td><input type="text" name="number_of_oil" size="3" maxlength="3" /></td>
</tr>
<tr>
<td> Spark plugs </td>
<td><input type="text" name="number_of_spark_plugs" size="3" maxlength="3" /></td>
</tr>
<tr>
<td> Adress</td>
<td><input type="text" name="adress"</td>
</tr>
<tr>
<td colspan="2" style="align: center"><input type="submit" value="Send order" /></td>
</tr>
</table>
</form>[/CODE]
<table style = "border: 0px;">
<tr style = "background: #cccccc;">
<td style = "width: 150px; text:align: center;"> Product </td>
<td style = "width: 15px; text-align: center;"> Quantity </td>
</tr>
<tr>
<td> Tires </td>
<td><input type="text" name="number_of_tires" size ="3" maxlength="3" /></td>
</tr>
<tr>
<td> Car oil </td>
<td><input type="text" name="number_of_oil" size="3" maxlength="3" /></td>
</tr>
<tr>
<td> Spark plugs </td>
<td><input type="text" name="number_of_spark_plugs" size="3" maxlength="3" /></td>
</tr>
<tr>
<td> Adress</td>
<td><input type="text" name="adress"</td>
</tr>
<tr>
<td colspan="2" style="align: center"><input type="submit" value="Send order" /></td>
</tr>
</table>
</form>[/CODE]