Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic newb i need help question. 1

Status
Not open for further replies.

unborn

Programmer
Jun 26, 2002
362
US
So every time i try learning php something goes wrong and i get discouraged. Well i just remembered these boards and decided its time to give it another shot so here goes nothing.

I am learning from a book and doing as i am told, i have even uploaded the examples to my website to make it easyer for me to see how it works while im coding it all in. i have coded all of chapter 2 and it was giving me an error or 2 .. and i tried their version and the same errors accured.. so with out further ado i shall share with you the error and codes.

error:
Bob's Auto Parts
Order Results

Order processed at 08:32, 19th June


Your order is as follows:
234 tires
34 bottles of oil
24 spark plugs


Total of order is 23 836.00

Address to ship to is sdf

Warning: fopen(/home/error-pr/public_html/../orders/orders.txt) [function.fopen]: failed to create stream: No such file or directory in /home/error-pr/public_html/test/examples/chapter02/processorder.php on line 63

Warning: flock(): supplied argument is not a valid stream resource in /home/error-pr/public_html/test/examples/chapter02/processorder.php on line 65


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



the bold is what the error is. i have everyhtign cmoded to 755 which is all access i have the folder created and all and i just dont under stand what im doing wrong :( heres a direct link.


thats all the source code.. the problem for now is with the processorders.php i have yet to see if view orders is working :(

heres the code anyways for the processorder.php


<?php
//create short variable names
$tireqty = $HTTP_POST_VARS['tireqty'];
$oilqty = $HTTP_POST_VARS['oilqty'];
$sparkqty = $HTTP_POST_VARS['sparkqty'];
$address = $HTTP_POST_VARS['address'];

$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
$totalqty = 0;
$totalqty += $tireqty;
$totalqty += $oilqty;
$totalqty += $sparkqty;

$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$date = date('H:i, jS F');

echo '<p>Order processed at ';
echo $date;
echo '<br />';
echo '<p>Your order is as follows:';
echo '<br />';

if( $totalqty == 0 )
{
echo 'You did not order anything on the previous page!<br />';
}
else
{
if ( $tireqty>0 )
echo $tireqty.' tires<br />';
if ( $oilqty>0 )
echo $oilqty.' bottles of oil<br />';
if ( $sparkqty>0 )
echo $sparkqty.' spark plugs<br />';
}

$total = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE;
$total=number_format($total, 2, '.', ' ');

echo '<P>Total of order is '.$total.'</p>';

echo '<P>Address to ship to is '.$address.'<br />';

$outputstring = $date.&quot;\t&quot;.$tireqty.&quot; tires \t&quot;.$oilqty.&quot; oil\t&quot;
.$sparkqty.&quot; spark plugs\t\$&quot;.$total
.&quot;\t&quot;. $address.&quot;\n&quot;;

// open file for appending
$fp = fopen(&quot;$DOCUMENT_ROOT/../orders/orders.txt&quot;, 'a');

flock($fp, LOCK_EX);

if (!$fp)
{
echo '<p><strong> Your order could not be processed at this time. '
.'Please try again later.</strong></p></body></html>';
exit;
}

fwrite($fp, $outputstring);
flock($fp, LOCK_UN);
fclose($fp);

echo '<p>Order written.</p>';

?>
</body>
</html>



in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Code:
$fp = fopen(&quot;$DOCUMENT_ROOT/../orders/orders.txt&quot;, 'a');

Why do you have the ../ in there?
The error message obviously tells that the file can't be found, thus not opened.

What is the real path to the file?
On the Web it is in test/examples/chapter02

All you need to replace is the ../ with the actual file path.

Also:
Do error checking. Use is_dir() to see if the folder exists and is_file() if the file is there to avoid these errors and present a nice error message.
;)
 
Just as a friendly comment, to help keep you from getting discouraged.

I strongly suggest installing a webserver on your local machine. As long you don't have security concerns (namely as long as no one can hit your machine from the outside world), just download and install PHP and Apache and your local box.

You'll save yourself countless frustrations when you just need to change one character... unless of course you're just ssh'd (or similar) into your webserver and editing it directly there, then just ignore me.

-Rob
 
you are my newbie god! :D

i thought that was messed up.. i didnt see how /../ would work.. but the book example had it so i figured &quot;hey the book knows what its doing&quot; :/ thanks alot! after more chmoding and another edit of the /../ i got it working! i was discuraged... but this helped like alot :D i thought it was a host problem liek they didnt enable somehting o.0

and ya once i learn more of php ill learn how to do is_file and is_dir.. im still newb dont think book has covered it yet hehe thanks a billion!

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
ssh? im on cable modem so uploading is pretty fast.. and i use cuteftp to edit files just right click the and click edit and edit it then exit and save it and it fixes it right on the server. id install php and stuff but im very low on space :(

heres one more question.. chmoding

ok

public (read,write,execute)
group (read,write,execute)
owner (read,write,execute)

i imagine owner always wants to have all activated... but for group and public what should i do.. i know what write does.. but read and execute? i would think same thing... or something (im just tryign to figure out so when i make somehtign others cant edit it just my scripts? or something.. i have it 755 so everyhtign is full access now, that bad? i did vb for 4 yrs havent done it in while.. and this is just nothing like vb :D haha

thanks for all yr help!

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
unborn,

All you need to make sure is that:

1. You are the owner with full rights
2. The web server can read the scripts
3. If writing by the webserver is permitted the folder needs to have write permissions for that user/group.

Whom are you concerned about? Are other people getting into your area?
 
thats the thing, no one yet. but once i get better at this i would like to open a community and i just wanna make sure no one can edit the files some how and mess up my work.

ty

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
-rwxrwxrwx
anyone can read/write the file if they have/gain access
to the directory

'x' aka execute is used by binary programs and scripting
languages: Perl, sh, etc...

a script without 'x' will bomb out with &quot;Bad Interpreter&quot;
thats pretty much what the x is for.

-rwxrwxrwx is tempting to use in the beginning, but when
your whole site is gone, or your system wont boot after a
long internet session, well, that MIGHT be the cause.
You dont always have control over this, be careful of
anything you add to your system you didnt create.
Dont be paranoid, just careful

Good luck...

skottieb:)
 
So basically make sure only the first x is there and not the other 2 because its group and public?

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Unless you are in a shared hosting environment which provides non-[tt]chroot[/tt]ed environment to the users, either through FTP or SSH, the permissions don't really matter, unless you use CGI.

//Daniel
 
ahh thanks.. i plan on using the cgi like features of php .. i havent gotten that far yet though so i dunno how to hahaha :D soon.. foudn otu this book is like close to 900 pages :( bleh.

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top