Jump to content

Archived

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

just-j

functions and variables help.

Recommended Posts

ok  im not going to put the exact code because i dont have it here with me.  but here what im trying to do
function BLABLA($var1, $var2)
{
echo $var1;
echo $var2;
}

$test1 = $_POST['bla1'];
$test2 = $_POST['bla2'];
BLABLA($test1, $test2);

thats not the exact code and not even what i want it to do.. im actually writing to a text file in the function.. but what happens is it writes $test1 $test2 to the file and not what is contained in the variable..  how do i get it to write what $test1 and $test2 is referring to instead of actually writing '$test1 $test2'??

Share this post


Link to post
Share on other sites
The code you've posted should work fine. Post the exact code that isn't working please.

Ken

Share this post


Link to post
Share on other sites
booted up my creation station (laptop)  here is the exact php code

[code]
<?php
function WriteTo($fileloc, $towrite) {
$fo = fopen($fileloc,"a+ ");
fwrite($fo, $towrite);
fclose($fo);
}
$user = $_POST['user'];
$bio = $_POST['bio'];
WriteTo('testing.txt', '$user $bio');
?>
[/code]


its writes $user $bio in the text file. i also tried takeing out the single quotes around $user $bio and i get an error when i do that.

one more thing.. if you can help me fix this, then how would i make it break to a new line at the end when writing to the text file.  instead of starting exactly where it left off?

Share this post


Link to post
Share on other sites
i think you can add \n or \r to the end of the $toWrite variable, i forget which one you should use

Share this post


Link to post
Share on other sites
ok  that answers that.. but what about the other problem.. the one im more conserned about...  please help

Share this post


Link to post
Share on other sites
what you want to do is this
[code]
WriteTo('testing.txt', $user . $bio);
[/code]

Share this post


Link to post
Share on other sites
i figured it out... putting the variables in "double quotes" worked..  now that /n /r thing.. i added it but it writes a little box in the .txt file this is the code fwrite($fo, $towrite /n);  what am i doing wrong.. i just want it to start a new line so when i write to the .txt file again it'll start on the new fresh line.

Share this post


Link to post
Share on other sites
the little box is the newline character, sometimes notepad freadks out on it, if you copy and paste it into say wordpad it will change it to a new line, try these two

fwrite($fo, $towrite . "/n");
fwrite($fo, $towrite . "/r");

im suprised php isnt throwing errors the way your doing your variables, if you are doing anything wih multiple variables(echo, print, functions, etc) then the . is your friend. it appends one variable onto the end of the other

Share this post


Link to post
Share on other sites

×

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.