Jump to content

functions and variables help.


just-j

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'??
Link to comment
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?
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.