kirstyburgoine Posted February 6, 2009 Share Posted February 6, 2009 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 Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/ Share on other sites More sharing options...
revraz Posted February 6, 2009 Share Posted February 6, 2009 Will it write static text? fwrite($fh, "This is a test"); Add error checking to your query $artresult=mysql_query($artquery) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/#findComment-755915 Share on other sites More sharing options...
kirstyburgoine Posted February 6, 2009 Author Share Posted February 6, 2009 Hi revraz, Yes it writes the static text. If I put $stringData = "www.mydomain.com/".$artdata['member_username'].""; it prints www.mydomain.com/ but not the variable Thanks Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/#findComment-755923 Share on other sites More sharing options...
revraz Posted February 6, 2009 Share Posted February 6, 2009 Then your query is failing. Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/#findComment-755926 Share on other sites More sharing options...
Mark Baker Posted February 6, 2009 Share Posted February 6, 2009 Well $username isn't a boolean, so "if ($username)" isn't a good test condition. Try using if (mysql_num_rows($artdata) > 0) Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/#findComment-755927 Share on other sites More sharing options...
omfgthezerg Posted February 6, 2009 Share Posted February 6, 2009 Is your query valid? Replace with this block of code... $artquery="SELECT * FROM `members` WHERE member_username='".$username."' AND okay=1"; $artresult=mysql_query($artquery) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/144066-writing-to-txt-file-using-php/#findComment-755930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.