Jump to content

New bie in php, please help


kjpr

Recommended Posts

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 by kjpr
Link to comment
Share on other sites

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 = on
Then 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 by requinix
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by kjpr
Link to comment
Share on other sites

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".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.