Hey everyone, first day newb here. I'm an old guy who used to do delphi so most stuff makes sense in that flowy sense anywho but I'm new to php and js so here I am.. Earlier I had an if/elseif turned switch/case question which answered itself here, so I'm hopeing for some more luck today here. I need to do three seperate files, one is just a simple counter the other two are mirrors of each other but saved at different times. If I can get the counter working, I shouldn't have any issue with the other two as they're just text logs. My issue is I can't get the file to open/create for me. I have the php file, and the directory it's in chmod 777 so it 'should' work, but it isn't. I'm open to any suggestions/comments/advice here. I just need to get this lil piece of stuff done by morning I hope. Here's the snippet I'm working with just to open/create the silly thing: // Vars $ordercount = "ordercounter.txt"; // Counter Log function counter(){ $fcount = fopen($ordercount, 'a') or die("uh-oh....."); $countData = "Test Data \n"; fwrite($fcount, $countData); fclose($fcount); } Code (markup): I haven't gotten to the counting part yet as I can't even get the silly thing to open/create itself.. Any/All help is greatly appreciated!
you can't access the $ordercount variable inside the function unless you either pass it as a parameter or declare it global. So it didn't work, because php didn't know what file to open: $ordercount = "ordercount.txt"; // either: function counter( $ordercount ) { $fcount = fopen($ordercount, 'a') or die("uh-oh....."); $countData = "Test Data \n"; fwrite($fcount, $countData); fclose($fcount); } // or: function counter() { global $ordercount; $fcount = fopen($ordercount, 'a') or die("uh-oh....."); $countData = "Test Data \n"; fwrite($fcount, $countData); fclose($fcount); } PHP:
Thank you Ed! The first option (easier one), didn't work for some reason, however the second options works perfectly! Now to figure out what other variables I have that need to be set global.. uhboy that could be a list... <sigh> always somethin aint it.. Thanks again Ed!