kjpr Posted September 5, 2013 Share Posted September 5, 2013 (edited) hello all, I am trying to save my form data to a local text file. but, seems like my php code is a bit wrong.i am not able to make it out.please help my html: <form method="post" action="Input1.php" name="form"> <label> New Data set: </label> <input type="radio" name="url" value="NetOptInput2.html" id="ex1" required/> Yes <input type="radio" name="url" value="NetOptResult2.html" id="ex2" required/> No <br><br><br> <label>Dataset description: </label> <input type="text" name= "Dataset" id="field1" size="30" placeholder="" readonly><br><br><br> <label>Token Number : </label><input type="text" name="Token Number" id="field2" size="6" placeholder="" readonly><br><br><br> <div style="text-align: center"><br> <input type="Submit" name="submit" value="Submit" class="submit"> <div class="spacer"></div> </form> my php: <?php if (isset($_POST['submit'])) { file_put_contents('C:\Users\ra\Desktop\input.txt', $_POST['Dataset'], FILE_APPEND | LOCK_EX); file_put_contents('C:\Users\ra\Desktop\input.txt', $_POST['Token Number'], FILE_APPEND | LOCK_EX); }; error_reporting(E_ALL); ?> Edited September 5, 2013 by kjpr Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2013 Share Posted September 5, 2013 (edited) Got a couple ); in the PHP that don't belong. There's also a harmless but unnecessary semicolon after the if block. [edit] Find your php.ini and set error_reporting = -1 display_errors = onThen restart your web server. With those changes you should get error messages from PHP that'll make it a lot easier to find where problems are. Edited September 5, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
kjpr Posted September 6, 2013 Author Share Posted September 6, 2013 I have set those options in php.ini and also removed extra ); from my PHP..i dont see any errors in the log but still its not working..please help. Quote Link to comment Share on other sites More sharing options...
requinix Posted September 6, 2013 Share Posted September 6, 2013 What's your code and how is it "not working"? Quote Link to comment Share on other sites More sharing options...
kjpr Posted September 6, 2013 Author Share Posted September 6, 2013 My aim is to save the form data into a text file..I have posted htmlcode and php script in the 1st post..if you could please take a look at it and let me know where i am going wrong, i would really appreciate it..thanks for looking into the issue. Quote Link to comment Share on other sites More sharing options...
requinix Posted September 6, 2013 Share Posted September 6, 2013 And that code you posted was flawed. What's your code now after the changes you said you made? Quote Link to comment Share on other sites More sharing options...
kjpr Posted September 6, 2013 Author Share Posted September 6, 2013 (edited) i didnt make any changes to my HTML. please take a look at the code below and let me know the flaws..thanks <form method="post" action="Input1.php" name="form"> <label> New Data set: </label> <input type="radio" name="url" value="NetOptInput2.html" id="ex1" required/> Yes <input type="radio" name="url" value="NetOptResult2.html" id="ex2" required/> No <br><br><br> <label>Dataset description: </label> <input type="text" name="Dataset" id="field1" size="30" placeholder="" readonly><br><br><br> <label>Token Number : </label><input type="text" name="Token Number" id="field2" size="6" placeholder="" readonly><br><br><br> <div style="text-align: center"><br> <input type="Submit" name="submit" value="Submit" class="submit"> <div class="spacer"></div> My new PHP <?php $savedata = $_REQUEST['savedata']; if ($savedata == 1){ $data = $_POST['Dataset']; $file = "C:/wamp/www/NetOptUI2/input.txt"; $fp = fopen($file, "a") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> my javascript inside html <script type="text/javascript"> $(function(){ $('form').submit(function(event){ event.preventDefault(); window.location = $('input[type=radio]:checked').val(); }); }); </script> <script type="text/javascript"> $(function(){ $("#ex1, #ex2").change(function(){ $("#field1, #field2").val("").attr("readonly",true); if($("#ex1").is(":checked")){ $("#field1").removeAttr("readonly"); $("#field1").focus(); } else if($("#ex2").is(":checked")){ $("#field2").removeAttr("readonly"); $("#field2").focus(); } }); }); </script> Edited September 6, 2013 by kjpr Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 6, 2013 Share Posted September 6, 2013 try change your file sting - it's a windows machine, so use the normal windows file system directory delimit's $file = "C:\\wamp\\www\\NetOptUI2\\input.txt"; also, you never close any of your input tags in the html, that's probably unrelated, but bad coding none the less I don't see anywhere that $_REQUEST['savedata'] is being set to "1". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.