Jump to content


Photo

writing multiple files


  • Please log in to reply
10 replies to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 04:26 AM

I have been trying to write multiple files at the same time and cannot seem to get it to write more than the first. It will write the first and go to write the second file, but then it stops and leaves the file blank. Im pulling variables from a form and having it write that value to a file, there are five total, but no matter what I do it will not write more than the first, help?


The "Change Colors" statement is the one with the five files that need to be written.

Here is where you can see the code...

[a href=\"http://nicotinejunkie.cv.vc/code.txt\" target=\"_blank\"]the code[/a]

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 March 2006 - 04:59 PM

You have a number of lines that look similar to:
<?php $fileclose($two); ?>
They probably should be coded as:
<?php fclose($two); ?>

I'm surprised that you didn't get sytax errors with this code.

Ken

#3 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 05:15 PM

Wow, I can't believe that I missed that! But, even with those changes, there is no luck. And my host has errors turned off. but, I will put them back on and edit this post if there are any errors...

**EDIT: still no luck, there are no erros...**

#4 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 09:03 PM

This is my most recent code, but same problem:
[a href=\"http://nicotinejunkie.cv.vc/code.txt\" target=\"_blank\"]Code[/a]

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 March 2006 - 09:51 PM

You still have syntax errors in this code. You have
<?php $fclose($two); ?>
instead of
<?php fclose($two); ?>
.

Can you post the code to the script that drives this code?

Ken

#6 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 11:54 PM

[!--quoteo(post=355690:date=Mar 16 2006, 05:51 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 05:51 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You still have syntax errors in this code. You have
<?php $fclose($two); ?>
instead of
<?php fclose($two); ?>
.

Can you post the code to the script that drives this code?

Ken
[/quote]

I have fixed the $fclose to fclose, but still no luck, the two codes are here:
[a href=\"http://nicotinejunkie.cv.vc/code.txt\" target=\"_blank\"]Code 1[/a]
[a href=\"http://nicotinejunkie.cv.vc/code2.txt\" target=\"_blank\"]Code 2[/a]

#7 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 12:14 AM

Never ever hide errors. That is a very big mistake. Fix your errors because if all you do is hide them sure no one sees errors, but the code does not give the desired results either. Hiding notices is fine, but never hide errors. Even if your code still seems to work fine, when you post it to another server which still reports errors your users are going to see errors.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#8 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 17 March 2006 - 12:34 AM

[!--quoteo(post=355735:date=Mar 16 2006, 08:14 PM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Mar 16 2006, 08:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Never ever hide errors. That is a very big mistake. Fix your errors because if all you do is hide them sure no one sees errors, but the code does not give the desired results either. Hiding notices is fine, but never hide errors. Even if your code still seems to work fine, when you post it to another server which still reports errors your users are going to see errors.
[/quote]

My host has errors turned off, in my code I have them turned with the ini_set, but no errors show...

#9 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 01:19 AM

I would talk to my host about this or find a better host. They are not the sharpest oranges in the toaster.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#10 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 March 2006 - 01:43 AM

You had a lot of redundant code...I think I eliminated most of it.

You also still had a few $ infront of fwrite and fclose fuctions. I've used servers before that will not show any syntax errors at all, even if error reporting is on and turned to E_ALL. It's irritating, to say the least.

Hope this helps, make sure to remove the spaces in all the file functions...the forum software doesn't like those functions.

<?php

$logfile = "log/log.txt";
$log = file_get_contents($logfile);
$date = date('l, F d, Y (g:ia)');
$ip = $_SERVER['REMOTE_ADDR'];

$user = $_POST['user'];
$pass = $_POST['pass'];
$action = $_POST['action'];
$filename = "usercomments/usercomments.php";
$filenametwo = "usercomments/lock.php";

$filetopcolor = "usercomments/topcolor.php";
$writetopcolor = $_POST['topbg'];

$filebottomcolor = "usercomments/bottomcolor.php";
$writebottomcolor = $_POST['bottombg'];

$filetopfont = "usercomments/topfont.php";
$writetopfont = $_POST['topfont'];

$filebottomfont = "usercomments/bottomfont.php";
$writebottomfont = $_POST['bottomfont'];

$fileborder = "usercomments/border.php";
$writeborder = $_POST['border'];

$write = "There are no comments.<br>";
$writetwo = "1";
$writethree = "0";

ini_set("display_errors", "1");
ini_set("error_reporting", "E_ALL");

if ($_POST[user] == "user") {
    if ($_POST[pass] == "pass") {

        if ($action == "Clear Comments") {
            $f ileopen = f open($filename, 'w') or die("Can't open file.");
            f write($fileopen, $write);
            $message = "The comments have been cleared.<br><br>";
            $logwrite = ("Comments cleared by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } else if ($action == "Lock Comments") {
            $fileopen = f open($filenametwo, 'w') or die("Can't open file.");
            f write($fileopen, $writetwo);
            $message = "The comments have been locked. <img src=images/clock2.png></img><br><br>";
            $logwrite = ("Comments locked by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } else if ($action == "Unlock Comments") {
            $fileopen = f open($filenametwo, 'w') or die("Can't open file.");
            f write($fileopen, $writethree);
            $message = "The comments have been unlocked. <img src=images/clock.png></img><br><br>";
            $logwrite = ("Comments unlocked by: " . $ip . " || " . $date);
            f close($fileopen);
            
        } elseif ($action == "Change Colors") {
            if ($writetopfont == null) {
                $message .= "No changes to $filetopfont<br>";
                $numberone++;
            } else {
                $fileopen = f open($filetopfont, 'w') or die("Cant open Top Font.");
                f write($fileopen, $writetopfont);
                $message .= "$filetopfont has been changed to $writetopfont<br>";
                f close($fileopen);
                $numberone++;
            }
            
            if ($writetopcolor == null) {
                $message .= "No changes to $filetopcolor<br>";
                $numbertwo++;
            } else {
                $two = f open($filetopcolor, 'w') or die("Cant open Top Color.");
                f write($two, $writetopcolor);
                $message .= "$filetopcolor has been changed to $writetopcolor<br>";
                f close($two);
                $numbertwo++;
            }
            
            if ($writebottomfont == null) {
                $message .= "No changes to $filebottomfont<br>";
                $numberthree++;
            } else {
                $three = f open($filebottomfont, 'w') or die("Cant open Bottom Font.");
                f write($three, $writebottomfont);
                $message .= "$filebottomfont has been changed to $writebottomfont<br>";
                f close($three);
                $numberthree++;
            }
            
            if ($writebottomcolor == null) {
                $message .= "No changes to $filebottomcolor<br>";
                $numberfour++;
            } else {
                $four = f open($filebottomcolor, 'w') or die("Cant open Bottom Color.");
                f write($four, $writebottomcolor);
                $message .= "$filebottomcolor has been changed to $writebottomcolor<br>";
                f close($four);
                $numberfour++;
            }
            
            if ($writeborder == null) {
                $message .= "No changes to $fileborder<br>";
                $numberfive++;
            } else {
                $five = f open($fileborder, 'w') or die("Cant open Border.");
                f write($five, $writeborder);
                $message .= "$fileborder has been changed to $writeborder<br>";
                close($five);
                $numberfive++;
            }
        }
    } else {
        echo "Invalid Password.";
    }
} else {
    echo "Invalid Username.";
}

//log write code
if ($logwrite != "") {
    $logwrite = "<table border=0 width=100%><tr><td vAlign=top align=left>-</td><td vAlign=top align=left>" . $logwrite . "</td></tr></table>";
    if ($log == "No log entries.") {
        $two = f open($logfile, 'w') or die("Cant open log.");
        f write($two, $logwrite);
        f close($two);
    } else {
        $two = f open($logfile, 'w') or die("Cant open log.");
        f write($two, $logwrite);
        f close($two);
    }
}

echo $message . "<a href=ap.php>Back to Admin Panel</a>";

?>


#11 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 17 March 2006 - 05:30 AM

My code works fine once you pull all of the "$" out of the file commands. Thanks for your help! I guess I was so frustrated that I couldnt get it to work, that I skipped over that all together, twice! Thank you so so much. I have been trying to get that to work for over a week....and phpfreaks wouldnt let me post >_< ...Thanks alot guys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users