Jump to content

requinix

Administrators
  • Posts

    15,264
  • Joined

  • Last visited

  • Days Won

    431

Everything posted by requinix

  1. What's this parse_blocks doing? Because if it's returning a whole bunch of information you don't want and the parts you do want aren't in the format you need, then shouldn't that be adjusted?
  2. No, that is not all of your code. Because it doesn't show what $rgy or $newamount are. The problem isn't the update itself. As gizmola suggested, the problem is going to be whatever sets up the different variables which the update uses.
  3. You make it sound like your question is "how do I find files with the setuid bit set" but you posted the answer yourself in one of those examples, so I don't think this is the question you actually want to ask. Maybe you mean to say "what's the difference between these commands?" in which case I would point you to the documentation to see what -mode and /mode mean. I think you have a more specific question to ask. One that directly answers something you aren't understanding. And it's probably not the first question you started with.
  4. Remember the part where I said you might not be validating transaction amounts? Did you look into that?
  5. We don't know anything about your application. If you wrote it and you don't know what happened, what would we be able to do? That said, my guess is an unvalidated input somewhere. Do you verify that all transactions must be for positive amounts?
  6. That's good. That's not good. For example, let me point out something: this shuffle($numbers); sort($numbers); randomly shuffles the $numbers and then sorts them in increasing order. It's nonsense, and not the sort of thing you should be trying to learn. "AI" is good at stringing words together in a way that, according to some calculated probabilities, hopefully make sense. But that is all it does - and it is certainly not intelligent. Be very careful with anything it says or creates.
  7. Nor are you expected to: Javascript development has these things called "libraries" which you can use to do the work for you.
  8. You're finding the one record that is the fourth lowest, right? If you're only finding one then it doesn't matter how you sort... But if you want to consider ties then you'll need a ranking-type solution anyways.
  9. Which is why many big supermarkets have an "index" somewhere: a sign or list listing a bunch of different types of items and which isles they're on. Because they want to make it easy to find things - but not too easy. But that aside, you're at least thinking like a user now in recognizing that going through a list of everything is too much - unless, perhaps, it's sorted (which supermarket isles aren't, but that's another story). So back to the webpage. You're looking for cookies. What do you want to do? Do you want to scroll through a list of categories until you find one that may or may not be applicable? Like you said, if I want cupcakes then it could be with breads or it could be with cookies, so there's still going to be some guesswork. Here's a more specific question: do you, as the user, actually care about the category? For example, if you could find cookies without having to know whether it's in the bread isle or the cookies isle, would you like that? Hint: go into the post editor box and type "@r"...
  10. Forget the technology, forget the dropdowns and the Javascript and the CSS, forget all the details for a minute and try to put yourself into the shoes of a user: You've been asked to provide the food you ate last. You can choose a type of candy, or a type of fruit, or a type of meat. What would you, as a user, ideally want to see in order for you to make the choice. Would you rather have one list of everything? Do you want to choose the type of food first and then the specific food second? Do you want all the lists of food available at once and you'll just pick one from the appropriate list? Something else? And does your answer change if you're on desktop vs mobile? Decide what the overall user experience should be, at a high level, as if by someone who doesn't understand web development, and create a UI to support it.
  11. You don't do any validation of $class to make sure it's a number between 8 and 55 before trying to use it with $days Same for $class as used with $periods, except values of 7, 8, 15, 16, 23, 24, and so on aren't valid You do a mysqli_connect for every single mysqli_query. All you need is one at the beginning of the script, then assign the connection to a variable and use that You're connecting as root, and without a password. Do things right and create a proper user with a proper password. If $whose is a string then don't put the variable directly into a query - use prepared statements instead Same for $sub, except it's even worse because that value came from the user, and a malicious user could easily screw up your database by doing something as simple as inserting an apostrophe And then you turn around and use $sub as a table name? That's completely wrong: never use unknown variables, especially from $_GET or $_POST, as table or column names. Fixing the above should resolve the error message too Why are there <br>s in your data? That doesn't make sense and suggests you're doing something weird with the data, like putting HTML into it. Using isset with the pwd in the $_POST only checks if there was a field named "pwd" in your form. If that field is left empty, isset will still return true. And assuming pwd is a password, shouldn't you be checking that password? When you do check the password, make sure that your code does not keep running after that. Right now the user will get redirected with some Javascript, yes, but all your code kept on running. And you're doing the thing where you use a variable as a table again, this time with $whose Are you putting multiple values into your $whose table? Don't. One value at a time, using multiple rows if you have to. On that subject, apparently $period is a column name? Don't. What you're doing with $day, where you have a column named "day" and multiple rows for the days, is what you should be doing with periods too. ...Are you putting an actual password into your form? And your own phone number as the sender? What's the point of the "msg" form field? Either that or what's the point of the "s" message you put into the session? What's going on with this? And why have a form that automatically submits? If you want to do something immediately then do it - don't send a form to the user (which they won't see for long) that is just going to come right back to you. All your various outputs need to be escaped with functions like htmlspecialchars so that someone like me can't insert <>s or "s that will mess up your HTML, or worse let me hijack some other user's browsing sessions for my own malicious purposes. Is this a school assignment or something?
  12. $ echo $0 -bash $ bash -c 'echo $0' bash $ bash -c 'echo $0' foo foo You can use -c if you want to run a command within bash - perhaps you need bash-specific features - and you aren't already running within bash. I'm not sure what's so complicated about that... Maybe it would be easier if you pointed out what you're confused about?
  13. https://www.regular-expressions.info/ has a decent tutorial/reference on regular expressions. ^ and $ are anchors that indicate the beginning and the end of the string, respectively, though that behavior can be slightly modified with flags.
  14. Did you consider trying them?
  15. Hard to help if you don't give any information.
  16. Same problem: March 30th - 1 month = February 30th -> March 2nd.
  17. Careful with dates like March 30th... Easiest method I know: date + mktime. $previous_month = date('Y-m', mktime(0, 0, 0, date('n') - 1, 1));
  18. This is an Apache question and not a PHP question, so now we're in the Apache forum. 1. Use SERVER_NAME instead of HTTP_HOST. After making sure your server is configured with the correct domain as the canonical name. 2. Instead of checking for https in one redirect and www in another, do both at the same time: if HTTPS is off or the HTTP_HOST != SERVER_NAME then redirect to the SERVER_NAME + REQUEST_URI.
  19. "Incorrect string value" means you're trying to insert data that isn't valid for the column. In your case, the column is defined as utf8mb4 (aka UTF-8) but your string is not UTF-8. If the value is binary data then do not use VARCHARs in the first place. Those are for character data. Use VARBINARY instead. https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html Either that, or you aren't supposed to be inserting raw binary data but either hex digits or a base-64 encoded version of the data...
  20. You and your server disagree about where the file is. You put it in the place you want it, and you know what the path is, but what you're telling the server is not the same thing. So let's see if we can't just resolve this immediately: 1. What is the full, absolute path to the PDF file as a file? Not a URL. I mean where it exists on your server - for example, /var/www/mywebsite/admin/assets/cvs/myfile.pdf 2. What is the full, absolute path to the PHP script you want to use to download the PDF file? If you still want one. You don't have to have it. 3. In case it's not obvious from those answers, what is the full, absolute path of where your website files are hosted? For example, /var/www/mywebsite.
  21. Either the path is wrong or the file is not where you think it is. I don't know what else to tell you. If the first one works then why do you want to change it?
  22. You've dumped a whole bunch of Javascript code and asked to "convert this from Javascript array". You need to be a LOT more specific about what you want help with because nobody here is going to read through that whole thing and try to guess what you want.
  23. No, the path is not correct. Because if it were then all this would be working, wouldn't it? If you want to link to the PDF in your HTML then read this and give it another try: https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls If you want to read the PDF with PHP code then read this one and give it another try: https://phpdelusions.net/articles/paths
  24. You can't encrypt the location because the end result is that you're still giving someone a URL to the file. Having gibberish instead of the word "documents" doesn't change that. The actual answer here is pretty simple: don't give direct links to your PDFs. Use a PHP script which authenticates the user and then outputs the file. You can use URL rewriting to transform /documents/whatever.pdf to something like /document.php?filename=whatever.pdf (which means existing URLs still work), then do something like <?php session_start(); if (!isset($_SESSION["userid"])) { // or whatever so you know if the user isn't logged in http_response_code(403); exit; } if (!isset($_GET["filename"])) { http_response_code(400); exit; } $filename = $_GET["filename"]; if (!preg_match('/^[a-z0-9_.-]+$/i', $filename)) { // potentially other characters in there http_response_code(404); exit; } $path = $_SERVER["DOCUMENT_ROOT"] . "/documents/" . $filename; // or whatever the path should be if (!is_file($path)) { http_response_code(404); exit; } $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $mime = [ // default $extension => "application/octet-stream", // list of file types you might have "pdf" => "application/pdf", // ... ][$extension]; header("Content-Type: $mime"); header("Content-Length: " . filesize($path)); header("Content-Disposition: inline;filename=$filename"); readfile($path);
  25. When you look at most sorts of Javascript UI frameworks, you see a common design: they keep an internal "model" of what the UI looks like, do work on that, and then update the actual UI with the changes. While it seems like a lot of extra work, it makes the design a lot simpler as you can manage the internal model whatever way you want instead of being forced to observe how the page is laid out. Repeating that concept here would be helpful. 1. For each row that you need to update, keep an internal array of the values of the 12 input boxes. Each one starts with a value of zero (apparently). 2. When an input is changed, go into that row's array and update the month's value. That's one half of the functionality: keeping track of when the value changes. Every time this process completes you'll have an array of the current values for the row. 3. Take that array and update the row's total. 4. Update the MS% value too? I don't know what that's supposed to be. That's the other half. Each of those halves can be done more-or-less independently of each other. Here is where I would say "Before I continue, let's clean up that HTML some because it's painful to look at" but that would take quite a bit of effort. So I won't. 😓 But there are some changes that would be really, really helpful: * Change the markup for the input boxes so that you don't have to list out the months so often by adding a data-month attribute for the month number (counting from 0) * Get rid of their IDs because (a) they're more often a bad thing than a good thing and (b) you aren't using them anyways <input type="number" class="form-control" name="Jan[]" value="" style="width:100%" data-month="0" required/> Then add some Javascript. * Don't use keyup. There's a perfectly good event exactly for this sort of thing: input * Instead of adding event handlers for every single month input, make use of the fact that Javascript "bubbles up" events and add a single event handler to cover all of them $(function() { // for each row in the table, $("#example tbody tr").each(function() { // the 12 values for the months const values = Array(12).fill(0); // a running total that can be updated every time a value changes let total = 0; // arrow function means "this" is inherited from the current scope (ie. this == the table row) const updateTotal = () => { $("[name='Total[]']", this).val(total.toString()); }; // every time something with a data-month changes its value, $(this).on("input", "[data-month]", function() { // get the new value const newvalue = parseInt(this.value || "0", 10); // update the running total total += newvalue - values[this.dataset.month]; // put the new value into the array values[this.dataset.month] = newvalue; // update the total updateTotal(); }); }); }); Demo: https://jsfiddle.net/gyhu2k57/
×
×
  • 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.