Jump to content

Write script to file.


MadnessRed

Recommended Posts

OK, basically I want a txt file with a load of variables that I can write to file.

 

for example if you enter Fred into an input, the files scipt.txt would show

 

$name=Fred

 

would this script work?

 

I can't see it working for me somehow though.

 

 

<?php

$filename = 'users.txt';


$comment = {
$friend1=$_GET["freind1"];
$url1=$_GET["url1"];
$pic1=$_GET["pic1"];
$friend2=$_GET["freind2"];
$url2=$_GET["url2"];
$pic2=$_GET["pic2"];
$friend3=$_GET["freind3"];
$url3=$_GET["url3"];
$pic3=$_GET["pic3"];
$friend4=$_GET["freind4"];
$url4=$_GET["url4"];
$pic4=$_GET["pic4"];
$friend5=$_GET["freind5"];
$url5=$_GET["url5"];
$pic5=$_GET["pic5"];
$friend6=$_GET["freind6"];
$url6=$_GET["url6"];
$pic6=$_GET["pic6"];
$friend7=$_GET["freind7"];
$url7=$_GET["url7"];
$pic7=$_GET["pic7"];
$friend8=$_GET["freind8"];
$url8=$_GET["url8"];
$pic8=$_GET["pic8"];
$friend9=$_GET["freind9"];
$url9=$_GET["url9"];
$pic9=$_GET["pic9"];
$friend10=$_GET["freind10"];
$url10=$_GET["url10"];
$pic10=$_GET["pic10"];
$friend11=$_GET["freind11"];
$url11=$_GET["url11"];
$pic11=$_GET["pic11"];
$friend12=$_GET["freind12"];
$url12=$_GET["url12"];
$pic12=$_GET["pic12"];
};

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename, 'a')) {
         echo "Sorry your comment wasn't posted.<br> Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $comment) === FALSE) {
        echo "Sorry your comment wasn't posted.<br> Cannot write to file ($filename)";
        exit;
    }

	echo "!Changes have been made!";

    fclose($handle);

} else {
    echo "The file $filename is not writable";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/105790-write-script-to-file/
Share on other sites

yep have now. neatened it up a bit, now got an error on line 22

 

new code

 

<?php

$filename = 'freinds.txt';


Line 22

$comment = {

$friend1="$_GET['freind1']"/n
$url1="$_GET['url1']"/n
$pic1="$_GET['pic1']"/n
$friend2="$_GET['freind2']"/n
$url2="$_GET['url2']"/n
$pic2="$_GET['pic2']"/n
$friend3="$_GET['freind3']"/n
$url3="$_GET['url3']"/n
$pic3="$_GET['pic3']"/n
$friend4="$_GET['freind4']"/n
$url4="$_GET['url4']"/n
$pic4="$_GET['pic4']"/n
$friend5="$_GET['freind5']"/n
$url5="$_GET['url5']"/n
$pic5="$_GET['pic5']"/n
$friend6="$_GET['freind6']"/n
$url6="$_GET['url6']"/n
$pic6="$_GET['pic6']"/n
$friend7="$_GET['freind7']"/n
$url7="$_GET['url7']"/n
$pic7="$_GET['pic7']"/n
$friend8="$_GET['freind8']"/n
$url8="$_GET['url8']"/n
$pic8="$_GET['pic8']"/n
$friend9="$_GET['freind9']"/n
$url9="$_GET['url9']"/n
$pic9="$_GET['pic9']"/n
$friend10="$_GET['freind10']"/n
$url10="$_GET['url10']"/n
$pic10="$_GET['pic10']"/n
$friend11="$_GET['freind11']"/n
$url11="$_GET['url11']"/n
$pic11="$_GET['pic11']"/n
$friend12="$_GET['freind12']"/n
$url12="$_GET['url12']"/n
$pic12="$_GET['pic12']"/n
};

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename, 'w')) {
         echo "Sorry your comment wasn't posted.<br> Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $comment) === FALSE) {
        echo "Sorry your comment wasn't posted.<br> Cannot write to file ($filename)";
        exit;
    }

	echo "!Changes have been made!";

    fclose($handle);

} else {
    echo "The file $filename is not writable";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/105790-write-script-to-file/#findComment-542150
Share on other sites

ok changed the { to "" which sorted out line 22

 

then it had a problem with line 23 because of the varialbe I guess

 

so I changes the $ to &#36;

 

now the problem is on line 24 because it doesn't like the & sign

 

anyway I though i would try and echo it first as if I could do that then it would be easier I think.

Link to comment
https://forums.phpfreaks.com/topic/105790-write-script-to-file/#findComment-542175
Share on other sites

still no luck tried using a /$ to show a dollar but its still not working, here is my echo code now, I think that if I can get it to work in echo it will be easier

 

<?php

$p1=""\\$friend1="$_GET['freind1']"\n"";
$p2=""\\$url1="$_GET['url1']"\n"";
$p3=""\\$pic1="$_GET['pic1']"\n"";
$p4=""\\$friend2="$_GET['freind2']"\n"";
$p5=""\\$url2="$_GET['url2']"\n"";
$p6=""\\$pic2="$_GET['pic2']"\n"";
$p7=""\\$friend3="$_GET['freind3']"\n"";
$p8=""\\$url3="$_GET['url3']"\n"";
$p9=""\\$pic3="$_GET['pic3']"\n"";
$p10=""\\$friend4="$_GET['freind4']"\n"";
$p11=""\\$url4="$_GET['url4']"\n"";
$p12=""\\$pic4="$_GET['pic4']"\n"";
$p13=""\\$friend5="$_GET['freind5']"\n"";
$p14=""\\$url5="$_GET['url5']"\n"";
$p15=""\\$pic5="$_GET['pic5']"\n"";
$p16=""\\$friend6="$_GET['freind6']"\n"";
$p17=""\\$url6="$_GET['url6']"\n"";
$p18=""\\$pic6="$_GET['pic6']"\n"";
$p19=""\\$friend7="$_GET['freind7']"\n"";
$p20=""\\$url7="$_GET['url7']"\n"";
$p21=""\\$pic7="$_GET['pic7']"\n"";
$p22=""\\$friend8="$_GET['freind8']"\n"";
$p23=""\\$url8="$_GET['url8']"\n"";
$p24=""\\$pic8="$_GET['pic8']"\n"";
$p25=""\\$friend9="$_GET['freind9']"\n"";
$p26=""\\$url9="$_GET['url9']"\n"";
$p27=""\\$pic9="$_GET['pic9']"\n"";
$p28=""\\$friend10="$_GET['freind10']"\n"";
$p29=""\\$url10="$_GET['url10']"\n"";
$p30=""\\$pic10="$_GET['pic10']"\n"";
$p31=""\\$friend11="$_GET['freind11']"\n"";
$p32=""\\$url11="$_GET['url11']"\n"";
$p33=""\\$pic11="$_GET['pic11']"\n"";
$p34=""\\$friend12="$_GET['freind12']"\n"";
$p35=""\\$url12="$_GET['url12']"\n"";
$p36=""\\$pic12="$_GET['pic12']"\n"";

echo "$p1$p2$p3$p4$p5$p6$p7$p8$p9$p10$p11$p12$p13$p14$p15$p16$p17$p18$p19$p20$p21$p22$p23$p24$p25$p26$p27$p28$p29$p30$p31$p32$p33$p34$p35$p3";
?>

Link to comment
https://forums.phpfreaks.com/topic/105790-write-script-to-file/#findComment-542224
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.