Jump to content

joshipoditunes

New Members
  • Posts

    3
  • Joined

  • Last visited

joshipoditunes's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank You both so much! @barand this error fix combined with a permissions fix Finally made it work! now for the next part: more checkboxes!!! Thanks!!
  2. I am trying to use $checked to set the checkbox default to "checked" if the txt file has a 1 in it. as for the fopen, thank you, I will start editing
  3. DISCLAIMER: this is my first time on this site, and I am a very beginning programmer still in high school, so please bear with any mistakes I might make. (if you have ANY advice or comments, feel free to share them with me, any help is appreciated) I am basically looking to make a series of css checkboxes (I only have one right now for testing purposes), which will submit onclick and store the value in a txt file. Upon loading, it will read that text document and set the checkbox default to what it was before. I could use the PHP session method, but I would like the default to carry on through reboots, etc. Currently, the file current.txt has a 1 in it, but the checkbox is still off. When I click the checkbox, it refreshes, but then goes back to off. any advice? <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> <body> <form action="index3.php" method="post"> <div class="onoffswitch"> <?php //writing to the file with the results of POST $my_filew = 'current.txt'; $handlew = fopen($my_filew, 'w'); if (isset($_POST["onoffswitch1"]) && $_POST["onoffswitch1"] == "on") { fwrite($handlew,'1'); fclose($handlew); } if (isset($_POST["onoffswitch1"]) && $_POST["onoffswitch1"] == "0ff") { echo "hello"; fwrite($handlew,'0'); fclose($handlew); } //reading from the file and setting the default $my_filer = 'current.txt'; $handler = fopen($my_filer, 'r'); $datar = fread($handler,filesize($my_filer)); fclose($handler); if ($data == 1) { $checked="checked"; } else { $checked=""; } //outputting the html $option='onclick="setTimeout(function() {submit();},1250);"'; echo '<input type="checkbox" name="onoffswitch1" class=onoffswitch-checkbox" id="myonoffswitch" '.$checked.' '.$option.'>'; echo "\n"; ?> <label class="onoffswitch-label" for="myonoffswitch"> <div class="onoffswitch-inner"> <div class="onoffswitch-active"><div class="onoffswitch-switch">ON</div></div> <div class="onoffswitch-inactive"><div class="onoffswitch-switch">OFF</div></div> </div> </label> </div> </form> </body> </html>
×
×
  • 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.