Need some help.

I am really new to php and mysql, I am currently going through a book, and I guess i need some
guidance. I am wondering, when writing to my .php file I have to use $_POST[""] in order to access a var. when its already declared in my .html file.

In the book I am trying to familiarize myself with fopen() and the current code i am working with is:

@$fp = fopen(“DOCUMENT_ROOT/…/orders/order.txt”; ‘w’); // <------------ line 57

if (!$fp)

{
echo "

Your order could…"
.“Please try again later.


EXIT;

}

Why am I getting Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’ in C:\Webdesign\wamp\www\hello.php on line 57. When all I am trying to do is get this error instead Warning: fopen(C:/wamp/www//…/orders/orders.txt) [function.fopen]: failed to open stream: No such file or directory.

Your syntax of arguments in fopen() function is incorrect. Correct is comma (while you have semicolon):
[php]@$fp = fopen(“DOCUMENT_ROOT/…/orders/order.txt”, ‘w’);[/php]

As for warning message failed to open stream: No such file or directory - you need to check path to the file you’re attempting to open.

Thanks for your post but I am still getting ( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’ in C:\Webdesign\wamp\www\hello.php on line 57. What I understand from reading this error is the variable $DOCUMENT_ROOT has not been declared in my code. I was under the impression that this was like a “predefined” variable within the PHP libraries. I did changed the “;” to “,” and I am still getting the same error. Thanks again for your help.

Try this predefined variable $_SERVER[‘DOCUMENT_ROOT’], or just specify relative path to the opening file.

$fp = fopen $_SERVER[‘DOCUMENT_ROOT/Webdesign/wamp/www/orders.txt’, ‘ab’];

Still getting the same error.

I guess I might not really know how I need to write this line of code.

Also I will give a better description on what I have had to do to get my program to run before trying this code. Maybe it will give a better idea on whats going on.

In my .html file I have writen this code:

In my .php file in order to use the variable “tireqty” i had to write $_POST[“tireqty”] * TIREPRICE instead of just using $tireqty * TIREPRICE.

Since I got the same error when trying to code in the way of $tireqty * TIREPRICE “( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’ in C:\Webdesign\wamp\www\hello.php on line 57”, I am assuming that I some how have to declare the variables.

You must be kidding?!

What did you mean by this code?
[php]$fp = fopen $_SERVER[‘DOCUMENT_ROOT/Webdesign/wamp/www/orders.txt’, ‘ab’];[/php]

Predefined variable name what I mentioned is $_SERVER[‘DOCUMENT_ROOT’]
If you want to concatenate two strings in PHP you need to use . (dot) operator, like this:
[php]$fp = fopen($_SERVER[‘DOCUMENT_ROOT’].‘Webdesign/wamp/www/orders.txt’, ‘ab’);[/php]

If you get an error again - double check the path to your orders.txt file!

I am looking to get a certain error, I am getting the T_VARIABLE error which means one of my variables is not declared. The path is correct I have checked and rechecked it. I will post my whole code. Note, I am a newb please understand that before judging me. I know there are simpler ways of doing some of the lines.

Bob's Auto Parts - Order Results!

Bob's Auto Parts

Order Results

<?php echo "Order Processed at "; echo date("H:i, jS F"); echo"
"; echo "Your order is as follows:"; echo"
"; define ("TIREPRICE", 100); define ("OILPRICE", 10); define ("SPARKPRICE", 4); ?>
<?php echo $_POST["tireqty"]; ?> tires<br>
<?php echo $_POST["oilqty"]; ?> oil<br>
<?php echo $_POST["sparkqty"]; ?> spark plugs<br>
<?php $totalqty = $_POST["tireqty"] + $_POST["oilqty"] + $_POST["sparkqty"]; $totalamount= $_POST["tireqty"] * TIREPRICE + $_POST["oilqty"] * OILPRICE + $_POST["sparkqty"] * SPARKPRICE; $totalamount = number_format($totalamount, 2); echo"
\n"; echo "Items ordered: ".$totalqty."
\n"; echo "Subtotal: $".$totalamount."
\n"; $taxrate = 0.10; // this is the local tax rate $totalamount = $totalamount * (1 + $taxrate); $totalamount = number_format($totalamount, 2); echo "Total including tax: $".$totalamount."
\n"; echo"
\n"; if ($totalqty == 0) { echo ""; echo "YOU DID NOT ORDER ANYTHING YOU FLAMING HOMO!
"; echo ""; } echo $_POST["address"]; echo " , is the address that the order will be shipped to." //open a file for appending. $fp = fopen($_SERVER['DOCUMENT_ROOT']. 'Webdesign/wamp/www/orders.txt', 'ab'); // <----- Line 57 if (!$fp) { echo "

Your order could not be processed at this time. " ."Please try again later.

" EXIT; } ?>

this is the error that comes up.

( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’ in C:\Webdesign\wamp\www\hello.php on line 57

Look at few lines above your line #57, you missed semicolon, thus the error message.
[php]echo " , is the address that the order will be shipped to."; // <---- NEED SEMICOLON HERE![/php]

Thank you so much. I feel like an idiot. That was the problem, but for some reason, my fwrites(), fopen(), ect… do not want to highlight (or turn blue) in notepad++. just wondering on this.

Sponsor our Newsletter | Privacy Policy | Terms of Service