chan95 Posted June 11, 2010 Share Posted June 11, 2010 Hi I'm trying to make a PHP file called store.php which stores the variables that are passed to it in a text file called data.txt. I want to make it so that if a user goes to http://www.mysite.com/store.php?myname=chan&myage=24, it will store myname and myage in that data.txt file. Could someone please help me do this? Link to comment https://forums.phpfreaks.com/topic/204496-storing-variables-in-txt-file-very-simple-question/ Share on other sites More sharing options...
kenrbnsn Posted June 11, 2010 Share Posted June 11, 2010 Use a database instead. Ken Link to comment https://forums.phpfreaks.com/topic/204496-storing-variables-in-txt-file-very-simple-question/#findComment-1070831 Share on other sites More sharing options...
chan95 Posted June 11, 2010 Author Share Posted June 11, 2010 Use a database instead. Ken Ok but I would rather just use a text file. Could you please tell me how to store the values in this text file? So far I have: <html> <head> <title>My Variables PHP Script</title> </head> <body> <p>The query string is: <?php echo $_SERVER['QUERY_STRING']; ?></p> <p>Myname: <? echo $_REQUEST['myname'] ?></p> <p>Myage: <? echo $_REQUEST['myage']; ?></p> <?php $handle = fopen("data.txt", "a"); fwrite($handle, "myname: $_REQUEST[1]"); fwrite($handle, "myage: $_REQUEST[2]"); fclose($handle); ?> </body> </html> But this code does not work. Link to comment https://forums.phpfreaks.com/topic/204496-storing-variables-in-txt-file-very-simple-question/#findComment-1070832 Share on other sites More sharing options...
kenrbnsn Posted June 11, 2010 Share Posted June 11, 2010 Why are you writing $_REQUEST[1] & $_REQUEST[2] when the values are in $_REQUEST['myname'] & $_REQUEST['myage']? Ken Link to comment https://forums.phpfreaks.com/topic/204496-storing-variables-in-txt-file-very-simple-question/#findComment-1070835 Share on other sites More sharing options...
chan95 Posted June 11, 2010 Author Share Posted June 11, 2010 Why are you writing $_REQUEST[1] & $_REQUEST[2] when the values are in $_REQUEST['myname'] & $_REQUEST['myage']? Ken Aha! That worked! Thanks so much! Link to comment https://forums.phpfreaks.com/topic/204496-storing-variables-in-txt-file-very-simple-question/#findComment-1070838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.