Jump to content


Photo

functions and variables help.


  • Please log in to reply
7 replies to this topic

#1 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 24 July 2006 - 05:12 AM

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'??


#2 kenrbnsn

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

Posted 24 July 2006 - 05:14 AM

The code you've posted should work fine. Post the exact code that isn't working please.

Ken

#3 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 24 July 2006 - 05:34 AM

booted up my creation station (laptop)  here is the exact php 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'); 
?>


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?

#4 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 24 July 2006 - 07:16 AM

i think you can add \n or \r to the end of the $toWrite variable, i forget which one you should use

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#5 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 24 July 2006 - 08:01 AM

ok  that answers that.. but what about the other problem.. the one im more conserned about...  please help


#6 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 24 July 2006 - 08:10 AM

what you want to do is this
WriteTo('testing.txt', $user . $bio);


[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#7 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 24 July 2006 - 08:58 AM

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.


#8 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 24 July 2006 - 04:32 PM

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

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users