• Log in or sign up for an account here: https://www.sythe.org/login

Simple file writing

MohtasaUnique

Grand Master
Joined
Sep 1, 2007
Sythe Gold
690
Messages
6,681
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:
Simple file writing
did you check this yet? just install xampp
 
Simple file writing
did you check this yet? just install xampp

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
 
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
 
Simple file writing
did you check this yet? just install xampp

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

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

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.

0909fad601.jpg


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:
Runescape Gamblingrunescape gambling
Back
Top