Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phreak3r

  1. @requinix I'm going to use as many tags as I need to. When I figure out a way to not have to use more than one I will eliminate one of the two. I didn't know inline event handlers were already outdated, I don't follow the corporation or industry standards. I guess I'll just figure it out. Thanks for the response though.
  2. I am trying to delete some videos. The videos are echo'd out individually with their own 'delete' input. The input value takes the id of the video, I didn't know of any other work around for that. I'd like to delete the video that corresponds with the button pressed, if that makes sense. Anyways, I would like to delete the video where the video id is equal to the video id of the input or the value of the input pressed. I am positive the way I am carrying this out is not correct, as I am thrown an 'index undefined error'. Here is the disgusting code at hand. Recommendations are appreciated, but please try and keep answers in line with the relevant information given. Thank You. <?php error_reporting(-1); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require('dbcon/dbcon.php'); include('header.php'); include('user.php'); $channel_id = $_SESSION['channel_id']; $query = $pdo->prepare("SELECT * FROM videos001 WHERE uploader = :channel_id"); $query->bindValue('channel_id', $_SESSION['channel_id']); $query->execute(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $title = $row['video_title']; $video_path = $row['video_path']; $video_id = $row['video_id']; /* - get videos of user - display videos out onto page */ ?> <html> <body> <div class="content"> <form method="post"> <h3><?php echo $title; ?></h3> <input type="button" name="delete" id="delete" value="<?php echo $video_id;?>" onclick="deleteVideo()"> </form> </div> </body> </html> <?php } function removeVideoFromFilesystem(PDO $pdo, $video_path, $video_id) { //chdir($video_path); //unlink($video_id . ".mp3"); $query = $pdo->prepare("DELETE from videos001 where video_id = :video_id"); $query->bindValue(':video_id', $_POST['delete']); $query->execute(); } if (isset($_POST['call_func'])) { removeVideoFromFileSystem($pdo, $video_path, $_POST['delete']); } ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function deleteVideo() { $.ajax({ url: 'dashboard.php', type: 'post', data: {"call_func":"1"}, success: function(response) { console.log(response); } }); } </script> </head> <body><?php print_r($_POST['delete']); ?></body> </html>
  3. I ended up copying the function from a StackOverflow answer. I am not familiar with some of the operations used in this function, but I will make an attempt to re-write it.
  4. @gw1500se When you upload a video to YouTube it tells you 'uploaded x seconds ago' 'uploaded x minutes ago'. I am trying to implement that feature to display the elapsed time, since each file upload if that makes sense.
  5. I wrote a function that grabs the elapsed time of a recently uploaded video. However, the time does not seem to increment. For example, if I upload a video, the time will display as '1 second'. However, if I continuously refresh the page, the time does not increment or increase. Any way to fix this? I figured I'd have to put it in some kind of loop (I do call the function in another class). function getElapsedTime($time) { $time = time() - $time; // get time since video upload date $time = ($time < 1) ? 1 : $time; $tokens = array( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : ''); } }
  6. How would you sanitize input without changing or mangling it?
  7. Never sanitize input, correct? I had asked the folks over at #php@freenode about that and they suggested I not sanitize input data.
  8. How can I go about validating a form in PHP? I am trying to do so, but I am clueless as to how to structure it.
  9. Do I only have to use Dependency Injection and pass in the instance of the helper class when the function I want to call contains a parameter? I did something similar, but the other function did not contain a parameter. Yet, the call to the function without the parameter went through and the function with the parameter gives me an error. Just trying to make sense of this.
  10. I am having an error here with my code/script. I try and call sanitizeData($data) from functions.php class in createUser.php class. I end up with an expected 'new' T_NEW error. createUser.php file <?php require('dbcon/dbcon.php'); include('fileUpload.php'); include('functions.php'); class createUser { public $functionsClassInstance = new helperFunctions(); public $avatar; public $bio; public $video_count; public $c_status; public $usernameI; public $username; public $password; public $email; public $doc; public $last_logged_in; public function addUser(PDO $pdo) { // add user info to db $avatar = "/soapbox/assets/soap.jpg"; $usernameI = $_POST['username']; $username = $functionsClassInstance->sanitizeData($usernameI); //$username = strip_tags(trim($_POST['username'];)) $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; date_default_timezone_set('UTC'); $doc = date("Y-m-d h:i:s"); // account date last seen/logged in // add account age $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio, doc, avatar) VALUES (:username, :password, :email, :cstat, :bio, :doc, :avatar)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email); $query->bindValue(':doc', $doc); $query->bindValue(':bio', $bio); $query->bindValue(':cstat', $c_status); $query->bindValue(':avatar', $avatar); // if user uploads file, add path and file to database and server, if not revert to default. if ($_FILES["avatar"]["error"] == 4) { $query->execute(); } elseif ($_FILES["avatar"]["error"] != 4) { $file = new fileUpload(); $file->processFile(); $avatar = "/soapbox/uploads/" . $_FILES["avatar"]["name"]; $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio, doc, avatar) VALUES (:username, :password, :email, :cstat, :bio, :doc, :avatar)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email); $query->bindValue(':doc', $doc); $query->bindValue(':bio', $bio); $query->bindValue(':cstat', $c_status); $query->bindValue(':avatar', $avatar); $query->execute(); } // create variables // initialize variables // bind values of variables being entered into database } } // this file is responsible for creating the users ?> functions.php class <?php // Functions are stored here // Any code that is repeated more than once is put into a function to make my life easier // The start of going from procedural to OOP // checks if user is logged in or not, limits access to certain pages in/on site. class helperFunctions { function sanitizeData($data) { strip_tags($data); trim($data); return $data; } } ?>
  • 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.