By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,630 Members | 1,510 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,630 IT Pros & Developers. It's quick & easy.

Writing input fields to a .txt file not working

P: 16
Hi All,

I am trying to write the name="fname" & name="age" to a .txt file, but it's not writing those two things to the file.


Expand|Select|Wrap|Line Numbers
  1. <?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
  8. <link rel="stylesheet" type="text/css" href="css/styles.css" />
  9. <script type="text/javascript" src="js/catalog.js"></script>
  10. <title>Catalog</title>
  11. </head>
  12. <body>
  13. <form id="frm1" name="myForm" onsubmit="return (validateForm() && checkRadios())" action="thankyou.php" 
  14.  
  15. method="post">First name: <input type="text" name="fname" />  Age: <input type="text" name="age" />  <input 
  16.  
  17. type="submit" name="submit" value="Submit" /> <input type="button" onclick="formReset()" value="Reset form" />
  18. <br />
  19. </body>
  20. </html>
  21.  
  22. <?php
  23. $iName = $_POST['fname'];
  24. $pAge = $_POST['age'];
  25. $data = "$iName | $pAge\n";
  26.  
  27. $fh = fopen("db\orders.txt", "a");
  28. fwrite($fh, $data);
  29.  
  30. fclose($fh);
  31. ?>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $iName = $_POST['fname'];
  3. $iAge = $_POST['age'];
  4. $data = "$iName | $iAge\n";
  5.  
  6. $fh = fopen("db\orders.txt", "a");
  7. fwrite($fh, $data);
  8.  
  9. fclose($fh);
Thanks,
T
Aug 15 '13 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,043
rewrite this:
Expand|Select|Wrap|Line Numbers
  1. $fh = fopen("db\orders.txt", "a");
  2. fwrite($fh, $data);
  3.  
to:
Expand|Select|Wrap|Line Numbers
  1. $fh = fopen("db\orders.txt", "a");
  2. if ($fh) { 
  3.   fwrite($fh, $data);
  4. } else {
  5.  echo "could not open file...";
  6. }
  7.  
just to make sure there are sufficient rights for opening this file.....
Aug 16 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.