SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    newbie in php,,,please help

    Hello all,

    my browser page is blank after hitting my submit button.seems like my php is not working..please take a look at my code and let me know where i went wrong..
    i am trying to save my form data in a local text file.
    i am new to php..
    thanks in advance
    my html:
    Code:
    <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:
    Code:
    <?php
    if (isset($_POST['submit'])) {
       file_put_contents('C:\Users\usiui\Desktop\input.txt', $_POST['Dataset'], FILE_APPEND | LOCK_EX););
       file_put_contents('C:\Users\usiui\Desktop\input.txt', $_POST['Token Number'], FILE_APPEND | LOCK_EX););
       };
       ?>
    please help

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    If the page is blank, that typically means there is a PHP error somewhere.

    To view the error message, you will need to enable error reporting:

    http://php.net/manual/en/function.error-reporting.php

    Code:
    error_reporting(E_ALL);
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Looks like you've got a few extra semi-colons in there
    PHP Code:
    <?php
        
    if (isset($_POST['submit'])) {
            
    file_put_contents('C:\Users\usiui\Desktop\input.txt'$_POST['Dataset'], FILE_APPEND LOCK_EX);
            
    file_put_contents('C:\Users\usiui\Desktop\input.txt'$_POST['Token Number'], FILE_APPEND LOCK_EX);
        }
    ?>

  4. #4
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is my HTML. please take a look at the code below and let me know the flaws..thanks
    Code:
    <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
    Code:
    <?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
    Code:
    <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>

  5. #5
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    This works fine if $_POST['Dataset'] has a value.
    PHP Code:
    <?php
    if (isset($_POST['Dataset'])){ 
    $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); 
    $message "Saved to $file successfully!";
    }
    ?>
    <html>
    <head>
    <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>
    </head>
    <body>
    <?php
    if (isset($message)){echo $message;}
    ?>

    <form method="post" action="" 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="" value="testing123" 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>
     </div>
     </form>
    </body>
    </html>

  6. #6
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your response.. i copied the code posted by you and tried.but, still its not working with the Dataset value set. please help.

  7. #7
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Try a relative path to file as that was what I was using for testing.

  8. #8
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried giving relative path too..No luck.please suggest.

  9. #9
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    None of the errors are showing, i.e. "Couldn't open input.txt for writing!"?

    ... and input.txt is not open in any editor?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •