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);
   ?>
Link to comment
https://forums.phpfreaks.com/topic/281902-new-bie-in-php-please-help/
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.

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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.