Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About jbonnett

  • Rank
    Regular Member
  • Birthday 09/01/1992

Profile Information

  • Gender
  • Location
    Aberystwyth, Wales
  1. There is a unique constraint on the column, transactions should work due to ACID. Also MySQL doesn't natively support base64.
  2. If you are wondering why I wanted to change to a non numerical system take a look at this: https://www.youtube.com/watch?v=gocwRvLhDf8 The video explains how it could be a security risk and how you can't have as many entries as the following. I also figured out how to do it with transactions, if you would like to know how I managed it for your future code here you go: try { $pdo->beginTransaction(); // start a transaction // create and execute query to see if the id exists (like the loop in my first post) // Add something to the database using the new id $pdo->commit(); // make the changes } catch (Exception $e) { $pdo->rollback(); // if it fails you can just take the database to the previous state }
  3. Thank you for the replies, I don't want a numerical id, also that loop will only keep looping if the id already exists. E.g. if it already exists generate another id. The generating function will eventually become custom, this is just for testing purposes. I realise the more rows the more likely it is to loop, although this is not the final code. Also you mention that it's a bad idea to create your own... My University seems to think not, as there are more combinations to be had with custom generators (if done the right way). They even use one themselfs. And knowing this is why I mentioned transactions as transactions allow you to work with existing data in a powerful way. Not meaning to come across as ungrateful, although I'm looking for this specifically and not the easiest way of achieving the somewhat same result.
  4. Hi All, I was wondering if there was a way that I could check if an ID already exists if not reserve it for the final query? Maybe with some sort of transaction based query. So if I were to do this: $exists = 1; while($exists > 0) { $new_id = uniqid(); $exists = $database->prepare('SELECT COUNT(*) FROM `Employees` WHERE `EmployeeID` = :EmployeeID'); $exists->execute([":EmployeeID" => $new_id]); $exists = $exists->rowCount(); } Along with: $query = $database->prepare(" INSERT INTO `Employees` ( `EmployeeID`, `Username`, `Password`, `FirstName`, `LastName`, `Email`, `Timestamp`, `Roles_Role` ) VALUES ( :EmployeeID, :Username, :Password, :FirstName, :LastName, :Email, :Timestamp, :Roles_Role ) "); $query->execute([ ":EmployeeID" => $new_id, ":Username" => $this->Username, ":Password" => $this->Password, ":FirstName" => $this->FirstName, ":LastName" => $this->LastName, ":Email" => $this->Email, ":Timestamp" => $this->Timestmap, ":Roles_Role" => $this->Roles_Role ]); $query->execute(); I may get an error where if I check if the new custom ID exists, if it doesn't then the next query may fail to duplicates. Thank you for any help in advance.
  5. I'm confused could you provide me with a more clear example? I'm thinking something more along the lines of: http://stackoverflow.com/questions/1038435/sql-conditional-select As I'm using PDO to Bind the value, but rather than making separate SELECT statements and all results (that may overlap all results from each into one, which would render it useless).
  6. There should be a way of doing this in SQL though, if I do it that way I'll have to check every combination.... e.g. if all exist, if only one exists, if only 2 exists .etc
  7. Hi All, I'm trying to check if an argument exists or is not null in postgres, rather than making an if / else statement for every single combination the arguments can be... So here's an example of what I'm trying to accomplish, I have an index page that can search by a text query, dropdown box of platform and a dropdown box of genre. That means I can have a combination of 6 different if / elses, if I added more well you get the idea that can be a lot of code. The simplest alternative I could come up with is getting all results from the database and excluding them all in the loop like so: // searching for a specific title if(isset($_GET["q"]) && $_GET["q"] !== "") { if(strpos(strtolower($game->title()),strtolower($_GET["q"])) === false) { continue; } } // searching by platform if(isset($_GET["platform"]) && $_GET["platform"] !== "all") { if(strpos(strtolower($game->platform()),strtolower($_GET["platform"])) === false) { continue; } } // searching by genre if(isset($_GET["genre"]) && $_GET["genre"] !== "all") { if(strpos(strtolower($game->genre()),strtolower($_GET["genre"])) === false) { continue; } } I have tried the SQL "SELECT * FROM videogames WHERE IF (:string IS NOT NULL) title ILIKE :string AND IF (:platform IS NOT NULL) platform = :platform AND IF (:genre IS NOT NULL) genre = :genre". I don't think I've done the if statement correctly in SQL either. Each of these arguments can exist or not. If you can think of a simple way to accomplish this please let me know.
  8. Hi All, I'm trying to use ajax to essentially get a page without changing anything already on the current page, so a modal shows after 29 mins and gives me the option to stop the user from logging out by clicking a button. The php session controls the logout by checking the session timestamp vs the one in the database, if the session one is older than 30 mins with no activity e.g. viewing a page... then logout. The problem is to "view" a page I use an ajax call (although it still logs the user out): $.ajax({ cache: false, type: "GET", dataType: 'html', url: "<?=$config["pre_link"].$_SERVER["REQUEST_URI"]?>", success: function(data) { }, error: function(){ }, complete: function(){ } }); Here is the whole thing if you need it: $(document).ready(function() { var timeout = setTimeout(function() { $("#logout_warning").modal('show'); }, 29*60*1000); var end = new Date().getTime(); function resetTimeout() { clearTimeout(timeout); timeout = setTimeout(function() { $("#logout_warning").modal('show'); }, 29*60*1000); end = new Date().getTime(); } $("#stop_logout").click(function() { resetTimeout(); $("#logout_warning").modal('hide'); $("#logout_warning .modal-content").css("display", "none"); $.ajax({ cache: false, type: "GET", dataType: 'html', url: "<?=$config["pre_link"].$_SERVER["REQUEST_URI"]?>", success: function(data) { }, error: function(){ }, complete: function(){ } }); }); $("#stop_logout .close").click(function() { $("#logout_warning").modal('hide'); $("#logout_warning .modal-content").css("display", "none"); }); var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var timer; function showRemaining() { var now = new Date().getTime(); var distance = ((end+30*60*1000) - now) - 1000; if (distance < 0) { clearInterval(timer); window.location.reload(true); return; } var days = Math.floor(distance / _day); var hours = Math.floor((distance % _day) / _hour); var minutes = Math.floor((distance % _hour) / _minute); var seconds = Math.floor((distance % _minute) / _second); //$("#logout_mins").html(minutes); $("#logout_secs").html(seconds); } timer = setInterval(showRemaining, 1000); });
  9. Nevermind I found the problem: private function parseURL() { if(isset($_GET["url"])) { return explode("/", filter_var(rtrim($_GET["url"], "/"), FILTER_SANITIZE_URL)); } } I fixed it by: private function parseURL() { if(isset($_GET["url"])) { return explode("/", str_replace('\/', ' ', filter_var(rtrim(str_replace(' ', '\/', $_GET["url"]), "/"), FILTER_SANITIZE_URL))); } } Do you have any ideas to make this better? Maybe a different character to make the spaces?
  10. If I don't encode the URL or decode it e.g. keep the white space in the URL, it works fine. I'm have my own MVC, I'm retrieving the URI via $_GET request forwarded to a function using call_user_func_array(), so I then do something like this: some_function($get = "") { if($get != "") { echo rawurldecode($get); } }
  11. Hey all, My URL is being sent as http://localhost/videos/On%20the%20go although if I use rawurldecode("On%20the%20go") I get "Onthego" rather than "On the go"... Any ideas? This should work, I've also tried urldecode() as it's a similar method but had no luck.
  12. You have posted the wrong code I would need to look at... Try posting: process_applicant.php myphpfunctions.php
  • 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.