Simple file writing

Discussion in 'Web Programming' started by MohtasaUnique, May 6, 2017.

Simple file writing
  1. Unread #1 - May 6, 2017 at 9:38 PM
  2. MohtasaUnique
    Joined:
    Sep 1, 2007
    Posts:
    6,678
    Referrals:
    2
    Sythe Gold:
    687
    Discord Unique ID:
    158831078964985856
    Discord Username:
    Tony#2235

    MohtasaUnique Grand Master
    Retired Global Moderator

    Simple file writing

    I'm trying to create a webpage for my personal trainer to use in order to let his members sign in for their sessions so he can keep track of how many sessions they've attended.

    I have all the visual shit set up, but I'm trying to understand how to make it write to a file. As I understand it, PHP requires a web server to write to files, but I want to know that I've correctly programmed the webpage so when I do upload it, it'll do as intended.

    Here's the code:

    HTML:
    <form method="post" action="script/write.php">
      <select name="member">
        <option class="holder" selected="selected">-MEMBER PROFILE-</option>
        <option value="test1">Test 1</option>
        <option value="test2">Test 2</option>
        <option value="test3">Test 3</option>
      </select>
      <input name="sessionDate" type="date"/>
      <input name="workoutPerformed" type="text" placeholder="WORKOUT PERFORMED"/>
      <button name="submitButton" class="checkinButton" type="submit">SUBMIT</button>
    </form>
    
    PHP:
    <?php
    if(isset($_POST["write"]) && !empty($_POST["workoutPerformed"])) {
        
    $f fopen("log.txt""a");
        
    fwrite($f$_POST["member"]);
        
    fwrite($f$_POST["sessionDate"]);
        
    fwrite($f$_POST["workoutPerformed"]);
        
    fwrite($f"\n");
        
    fclose($f);
        echo 
    'alert("Success")';
        die():
      }
    else() {
        echo 
    'alert("Error")';
    }
    ?>

    I've currently got it running on a local directory on my computer, but obviously I don't have apache so PHP isn't functional.... Can anyone confirm if this is all I need in order to write files?
     
    Last edited: May 6, 2017
  3. Unread #2 - May 16, 2017 at 9:27 PM
  4. Brian
    Joined:
    Feb 23, 2011
    Posts:
    977
    Referrals:
    0
    Sythe Gold:
    565
    Discord Unique ID:
    766792808848687124
    I'm LAAAAAAAME Lawrence Extreme Homosex

    Brian brian#8700 / Discord ID 766792808848687124
    $200 USD Donor New

    Simple file writing

    did you check this yet? just install xampp
     
  5. Unread #3 - Jun 18, 2017 at 10:34 AM
  6. Worm
    Joined:
    Feb 12, 2016
    Posts:
    849
    Referrals:
    1
    Sythe Gold:
    1,104
    Vouch Thread:
    Click Here
    Discord Unique ID:
    173475831002300431
    Discord Username:
    Worm
    Poképedia

    Worm Apprentice
    $50 USD Donor New

    Simple file writing

    I personally suggest WAMP or xampp
    WampServer

    I find it easier to setup out of the box vs other self-hosted server systems.

    If you need help setting up Wamp/Xampp, contact me Motasha
     
  7. Unread #4 - Jun 23, 2017 at 11:08 PM
  8. Brian
    Joined:
    Feb 23, 2011
    Posts:
    977
    Referrals:
    0
    Sythe Gold:
    565
    Discord Unique ID:
    766792808848687124
    I'm LAAAAAAAME Lawrence Extreme Homosex

    Brian brian#8700 / Discord ID 766792808848687124
    $200 USD Donor New

    Simple file writing

    I've been told to use nginx instead of apache.. I haven't set it up yet but maybe it's better to test with that than to continuet o test with apache stacks
     
  9. Unread #5 - Jun 24, 2017 at 12:16 AM
  10. MohtasaUnique
    Joined:
    Sep 1, 2007
    Posts:
    6,678
    Referrals:
    2
    Sythe Gold:
    687
    Discord Unique ID:
    158831078964985856
    Discord Username:
    Tony#2235

    MohtasaUnique Grand Master
    Retired Global Moderator

    Simple file writing

    I figured it out, my mistake was not realizing, for obvious security reasons, you can't write files without a web server as you guys posted. I was trying to run it from a local directory on my computer.

    Uploading it to a free web host that provides apache support, and majorly tweaking the program made it work properly.

    for those interested, here's the final result and code. It's basic shit, I know, but maybe some noob like myself can learn from it.

    [​IMG]

    HTML:
    <!doctype html>
    <html lang="en">
      <head>
            <meta charset="utf-8">
            <title>Fitness Life Consulting, Inc.</title>
            <meta name="description" content="Training Session Login">
            <meta name="Author" content="Tony White | &#9400; 2017 Fitness Life Consulting, Inc.">
            <link rel="stylesheet" href="css/stylesheet.css">
            <script>
                function myFunction() {
                alert("ENJOY YOUR WORKOUT!");
                }
            </script>
        </head>
        <body>
            <div class="content">
                <div class="headerLeft">
                    Member Check-in
                </div>
                <div class="headerRight">
                    <a href="/logs/"><img src="images/logo.png" /></a>
                </div>
                <div class="clearFloat"></div>
                <div class="formWrapper">
                    <form method="post" action="write.php">
                        <select name="member">
                            <option class="holder" selected="selected">-MEMBER PROFILE-</option>
                            <option value="Luis Cardona">More options</option>
                        </select>
                        <input name="sessionDate" type="date"/>
                        <input name="workoutPerformed" type="text" placeholder="WORKOUT PERFORMED"/>
                        <button name="submitButton" class="checkinButton" type="submit" onclick="myFunction()">SUBMIT</button>
                    </form>
                </div>
            </div>
            <div class="copyright">
                &#9400; 2017 Fitness Life Consulting, Inc
            </div>
        </body>
    </html>
    PHP:
    <?php
        $f 
    fopen('logs/log_'.date('m-d-Y').'.txt'"a");
        
    fwrite($f$_POST["member"]);
        
    fwrite($f"\t");
        
    fwrite($f$_POST["sessionDate"]);
        
    fwrite($f"\t");
        
    fwrite($f$_POST["workoutPerformed"]);
        
    fwrite($f"\n");
        
    fclose($f);
        
    header('Location: index.html');
        exit();
    ?>
    HTML:
    body {
      margin: 0;
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    }
    
    html {
      background: url('../images/background_image.jpg') no-repeat center center fixed;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    }
    
    .content {
      background-color: #e2e2be;
      margin: 175px auto 10px auto;
      width: 450px;
      border-radius: 0.5em;
      padding: 30px;
      opacity: .85;
    }
    
    .copyright {
      padding: 10px;
      color: white;
      margin: auto;
      text-align: center;
      opacity: .7;
    }
    
    .headerLeft {
      float: left;
      display: block;
      width: 50%;
      padding: 20px;
      box-sizing: border-box;
      font-size: 18px;
      font-weight: bold;
      color: #4E7C32;
      text-transform: uppercase;
    }
    
    .headerRight {
      float: right;
      display: block;
      width: 50%;
      box-sizing: border-box;
      text-align: right;
    }
    
    .headerRight img {
      width: 200px;
      margin: 0;
      padding: 0;
    }
    
    .clearFloat {
      clear: both;
    }
    
    .formWrapper {
      padding: 20px;
      margin: auto;
      text-align: center;
    }
    
    .checkinButton {
      margin: 10px;
      width: 320px;
      height: 55px;
      -webkit-border-radius: 5;
      -moz-border-radius: 5;
      border-radius: 5px;
      font-family: Arial;
      color: #ffffff;
      font-size: 20px;
      background: #cc3300;
      padding: 10px;
      text-decoration: none;
      border: none;
      -webkit-transition: background 0.3s;
      -moz-transition: background 0.3s;
      -o-transition: background 0.3s;
      transition: background 0.3s;
    }
    
    .checkinButton:hover {
      background: #ff4000;
      text-decoration: none;
    }
    
    input {
      padding: 10px;
      margin: 10px;
      width: 300px;
      height: 35px;
      border-radius: 0.5em;
      border: none;
      border-bottom: solid 2px #cc3300;
      -webkit-appearance:none;
      -webkit-transition: border 0.3s;
      -moz-transition: border 0.3s;
      -o-transition: border 0.3s;
      transition: border 0.3s;
      text-align: center;
    }
    
    select {
      padding: 10px;
      background-color: white;
      margin: 10px;
      width: 320px;
      height: 57px;
      border-radius: 0.5em;
      border: none;
      border-bottom: solid 2px #cc3300;
      -webkit-appearance:none;
      -webkit-transition: border 0.3s;
      -moz-transition: border 0.3s;
      -o-transition: border 0.3s;
      transition: border 0.3s;
      text-align: center;
    }
    
    input:focus, select:focus, .style-4 .focus {
      border-bottom: solid 2px #ff4000;
      outline: none;
    }
    
    input:focus::-webkit-input-placeholder {
      color: transparent;
    }
    
    input::-webkit-inner-spin-button {
      display: none;
    }
    
    input::-webkit-calendar-picker-indicator {
      opacity: 1;
    }
    
    select:focus option.holder {
      display: none;
    }
     
    Last edited: Jun 24, 2017
< need some instruction on form | >

Users viewing this thread
1 guest


 
 
Adblock breaks this site