Writing to .txt file using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KirstyBurgoine
Forum Newbie
Posts: 3
Joined: Tue Apr 22, 2008 1:59 pm

Writing to .txt file using php

Post by KirstyBurgoine »

Please somebody help me, I am trying to do something that I thought would be very simple!

I have a navigation bar that has been created in Flash, I need the URL to change depending on how somebody enters the site. What I thought would be the easiest would be to write my PHP so that I print the correct URL to a text file that flash then links to so the button works correctly.

This is my php:
<?
//Pull username from URL
$username = $_GET['member_username'];

$artquery="SELECT * FROM `members` WHERE member_username='".$username."' AND okay=1";
$artresult=mysql_query($artquery);
$artdata=mysql_fetch_assoc($artresult);

// write url to text file

$myFile = "navigation.txt";
$fh = fopen($myFile, 'w+') or die("can't open file");

if ($username) {
$stringData = "/".$artdata['member_username']."";

} else {
$stringData = "/index.php";
}

fwrite($fh, $stringData);

fclose($fh);
?>

My problem is that I cannot get a variable to print to the text file. I've tried replacing $artdata['member_username'] $member and adding this $member = $artdata['member_username'], I've also tried pulling the username directly from the url using $_GET['member_username'] but still no joy!

Does anyone know why this would be?

Thanks

Kirsty
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Writing to .txt file using php

Post by susrisha »

how are you making a request url??

it should be like
http://www.linktophp.php?member_username="valueto be sent"

If thats the format.. just put an echo for $_GET['member_username'] to see if the variable is passed correctly
Post Reply