Jump to content

requinix

Administrators
  • Posts

    15,041
  • Joined

  • Last visited

  • Days Won

    413

Community Answers

  1. requinix's post in Tables in posts was marked as the answer   
    How about this? It's the table button next to the bullet and numbered list buttons.
  2. requinix's post in install desktop entry was marked as the answer   
    Yeah no, there would definitely be no such thing. That's way too specific for PHP.
  3. requinix's post in Wordpress search engine (searchwp) was marked as the answer   
    Go to the page in question, do a View Source in your browser, and find the HTML for your form. What is the value of the form's action?
  4. requinix's post in directory file list was marked as the answer   
    One-liners are great and all, but is it worth all the time you've spent on it so far? A simple foreach loop could have solved the problem hours ago.
  5. requinix's post in Integer precision issue was marked as the answer   
    That's floating-point arithmetic: the computer can't calculate 573.06 * 100 exactly so it comes up with something close. Something like 57305.9999999999986. And if you truncate that, like with an int cast, then you'll just get 57305. In other cases it might come up with 57306.00000000000005.
    The solution is super simple: round the number instead of truncating it.
    function convertToMoneyInteger($input) { return round($input * 100); } Be careful that your $input is never going to have fractional cents or you'll lose them by rounding to 0 digits. If you're concerned that might be possible, round to an appropriate number of decimal places.
  6. requinix's post in getting the deeper click event was marked as the answer   
    Not quite. Yes, it's displaying the confirmation after you click the button, but it's not displaying it because you clicked the button. What's happening is that you clicked the button (event #1) and then the button, having no other behavior imposed on it to override the default, causes the form to submit (event #2), and that shows the confirmation.
    Additionally, "srcElement" is old, and what you should be using instead of it is "target". And that name communicates the purpose better: it isn't the "source element" of an event, which suggests that it's some element responsible for the event, but rather it's the target of the event - the thing the event is addressing.
    It's a distinction that matters because of how events work and the fact that you can - and will, if you're not careful - receive events for child elements.
    So the target (aka srcElement) during the onsubmit is going to be the form. Not whatever thing that you interacted with that set about the chain of events causing the form to be submitted, but the form the event is associated with.
    Or another way to think about it is, your code is paying attention to the form being submitted when you actually wanted to pay attention to a button being clicked, and that mismatch is your problem.
    But anyway, that "receive events for child elements" thing I said earlier is useful because it means you have a way to listen for a click event on any button in the form by listening to the form itself. That means you don't have to loop over the form's buttons, and you can use a single event handler.
    jQuery makes doing this easy because you can tell it to (1) listen to the form (2) for a click event (3) triggered by a button.
    $("#myform").on("click", "button.form-button", () => { ... }); Native DOM only does the first two parts so you have to handle the third yourself, which isn't hard since .matches exists.
    document.querySelector("#myform").addEventListener("click", (e) => { if (e.target.matches("button.form-button")) { // e.target is the button, e.currentTarget is the form } });  
  7. requinix's post in Injecting a debug object more than 2 levels. was marked as the answer   
    Then all I can tell you is you're doing something differently in this third class that you were/weren't doing in the other two classes.
    Because PHP isn't going to care about how far from the "top" you are: an object is an object. If you can do ->debug on a particular object from one place then* you can do the same ->debug on the same object from a different place.
    Alright. But one question:
    Doing what another way?
     
    * Technically that's not always the case, but it shouldn't be an issue as far as this is concerned.
  8. requinix's post in Crawled websites not inserting into my SQL table | PHP Web Crawler was marked as the answer   
    if (!empty($titleElements)) { You didn't define $titleElements. Thus the $title is empty...
  9. requinix's post in Power App Button Error was marked as the answer   
    Sounds like you're not submitting the data in the format the API requires. Check the documentation for what you should be doing and compare it to what you are actually doing.
    Also, maybe it's just me, but shouldn't that "Select Date" have, you know, some kind of date field associated with it? It's just empty...
  10. requinix's post in Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at least 2 arguments, 1 given in on line 19 was marked as the answer   
    Here's the code you have:
    $query_result = mysqli_query($query); The "procedural style" mentioned in the docs shows this:
    mysqli_query(mysqli $mysql, string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool You read it like this:
    1. This is a function named "mysqli_query"
    2. The first parameter is called $mysql - at least in the documentation itself, you can name your variables whatever you want - and it is a mysqli (that's a class) value
    3. The second parameter is called $query and is a string value
    4. The third parameter is called $result_mode and is an int(eger) value; it has a default value of MYSQLI_STORE_RESULT, which will apply when you do not pass a third argument
    5. The function returns a value that is mysqli_result|bool, meaning it will be a mysqli_result (another class) value or a bool(ean) value
    The Parameters section gives more details about those three parameters. Same for the Return Values section and the return value.
    There's also an Errors/Exceptions that is useful to understand when and why the function may or may not behave correctly.
    But back on topic:
    The first parameter is not optional - there is no default value, so you must provide one yourself. You have done so with your $query variable; remember, your variable can be named whatever you want.
    But there's a problem: the parameter is supposed to be a mysqli value, and you provided a query string.
    The second parameter is not optional either, however you are not providing one. That's what PHP is complaining about.
    If you combine those two facts together, the problem should be pretty clear: you need to call the function with a mysqli and a query string, but you only called it with a query string.
    I'm guessing this was originally based on mysql (no 'i') code? There is a mysql_query function but it isn't the same as the mysqli_query function.
  11. requinix's post in Inserting data into 3 tables, one after the other was marked as the answer   
    To make sure I understand, you have two options:
    (a) Do three normal INSERT statements, and get the auto-incremented IDs of what you need
    (b) Do a normal INSERT and then craft a couple INSERT...SELECT queries based on the raw values you want to insert plus a reference or two to the IDs of the new rows you created that hopefully don't have any duplicates
    I'm thinking you should go for the simpler option.
  12. requinix's post in How to debug an issue in a web server where some users are getting SSL error? was marked as the answer   
    Your first goal should be to reproduce the problem - because you can't know what to fix if you don't know what it is, and if you can't reproduce the problem then how will you know if your fix is working?
    1. Gather more information. What SSL error? Surely there's some more specific information someone can give you? Like an actual error message, maybe?
    2. Apply some logic. Which users are seeing this? What do they have in common? Do they have anything in common at all? Can the users successfully log in at another time?
    3. Think about it from a technical standpoint. There are tons of possible SSL errors (see action item 1) but most of them boil down to the server not giving an appropriate cert. Do you have multiple servers? Is there a load balancer? Geographic CDNs? Are you sure they're all configured with identical information and up-to-date certificates?
    4. Examine the details. "Certain static content not found" isn't any error message I've ever seen before - assuming it's a literal message. Where is it coming from? Under what conditions will it be emitted?
  13. requinix's post in My website won't update records in my SQLyog Database was marked as the answer   
    How do I ask a good question?
  14. requinix's post in Avoid inheritance with exceptions was marked as the answer   
    Probably.
    Inheritance represents an "is a" relationship. Would it be accurate to say that your custom exception class "is an" InvalidArgumentException? If I had code that caught InvalidArgumentException, should that code also be able to catch your exception?
    Composition represents a "has a" relationship - or "needs a", or something else similar to that. Would it be accurate to say that your exception class "has an" InvalidArgumentException? Is your class a distinct form of exception separate, but not entirely unrelated to, an InvalidArgumentException?
    The answer seems like it would be the first one, however the $otherDetails is suspicious and suggests something more than an invalid argument, thus perhaps composition is more appropriate, however the fact that you chose to make it anonymous means it will be impossible to catch or type guard for that particular class in the first place, which makes composition almost useless.
    In other words, your example doesn't make sense. If you want a special exception class then it should be a full named class. If you want special exception data then it needs to be a full named class.
    And that is the real code smell.
  15. requinix's post in Lost in geolocation was marked as the answer   
    That's not an error. That's a link. Specifically, a link to https://goo.gl/Y0ZkNV.
    Pay more attention.
    Not if you want to do this from Javascript. But you should change to HTTPS regardless.
    To do it from PHP, if you can accept that you will not get an accurate location, you look up the remote IP address in some geolocation database - MaxMind's, for instance.
  16. requinix's post in Using SSL for connection to database server was marked as the answer   
    SSL is only if you are not using a Unix socket. Which you are. So you don't need it.
  17. requinix's post in Different regular expression match result in PHP 7.4.11 and 7.4.12 was marked as the answer   
    Most of the time, when you find an oddity like this that can't be explained any other way, the answer is going to be a JIT thing: PCRE isn't supposed to, but occasionally does behave in slightly different ways when JIT is on or off.
    ini_set("pcre.jit", 0); preg_match('/([^\.]|^)\s*a/', "a", $matches); But turning off JIT is not the best answer. Instead, do what kicken did and tweak the expression so it works.
    Anyway, that expression really should work even with JIT enabled, so feel free to file a bug report against PCRE2 about it.
    https://github.com/PCRE2Project/pcre2/issues
  18. requinix's post in How to stop google from flagging my site as Dangerous/Fishing. was marked as the answer   
    If I plug your site into that reporting link I gave earlier, it says there's nothing wrong. And if I visit it in my browser, it has no complaints.
    Has the problem gone away? Because unless you can find out why the site is (was) marked as unsafe, it'll be hard to fix it to be safe.
  19. requinix's post in NSFW filter conditionals was marked as the answer   
    If you know that the form was submitted then you could take the absence of a value as proof that it was unchecked.
    But yes, there is a simple solution that lets you keep checkboxes: use hidden inputs.
    <input type="hidden" name="checkbox" value="off"> <input type="checkbox" name="checkbox" value="on"> When checked, the checkbox's "on" overwrites the hidden input's "off".
  20. requinix's post in Get data out of array without for each was marked as the answer   
    "Simple" string interpolation only allows you to access a single level of an array. If you want multiple levels then use the "complex" syntax with braces:
    "value='{$rows[0]['itemName']}'>"  
  21. requinix's post in Redirect using special function was marked as the answer   
    Okay yeah no, you're missing the point.
    Look at this:
    <a class="color_black" id="btn" href="?dashboard=user&page=member&tab=viewmember&action=view&member_id=<?php echo esc_attr($retrieved_data->ID)?>"> You know what URL you want the user to go to. After all, it's right there in the link.
    So if you know what the URL is, why even bother having this page at all? Why give the user some HTML page when all you're going to do is trigger some Javascript that immediately sends them somewhere else? It's wasteful.
    Instead of giving them this page, do the redirect.
    In case you weren't aware, you can do it with some PHP code. Maybe that was the missing piece in this puzzle? It looks like this:
    $url = "?dashboard=user&page=member&tab=viewmember&action=view&member_id=" . esc_attr($retrieved_data->ID); header("Location: $url"); You execute that code before making any output at all. None at all. Then you stop executing after that - so no output after it either.
    And that's how you do a redirect from within PHP. One that doesn't require any HTML or Javascript.
  22. requinix's post in Passing Variables From Function to Function was marked as the answer   
    You've skipped past one very particular problem: you want an existing menu item's text to reflect something that can change. Using a variable for the addItem's label doesn't mean that you can change the variable's value later and the label will update. You would have to add and remove these items every time the custom-lc is clicked.
    So the truth is actually that no, the code you've posted doesn't work. Not that you're using it wrong but that it can't do what you want. And I don't see anything in the library you're using that lets you edit menu labels.
    I'm not sure how you came across that library, but when I search for "jQuery context menu" the very first result is this one, which looks like a much better option given that it's been updated during this year and, you know, it has actual documentation.
  23. requinix's post in XAMPP for Linux 8.2.4 - could not see javascript file was marked as the answer   
    1. You're using XAMPP on Linux? 😆 Just install Apache, PHP, and whatever else you need through your package manager. Normally.
    2. It's code. Singular. "Codes" are things you enter into videogames.
    3. Don't reference w3schools. Sometimes they tell you the right thing to do, sometimes they tell you the wrong thing to do, and if you're learning then you won't be able to tell the difference between them.
    Where did you put main.js? /opt/lampp/htdocs/js/main.js? Then the first form you had is correct. If not then (a) why not? and (b) the second form was correct (except "js/main.js" - no ./ - is cleaner and means the same thing), however you might discover problems with this approach...
    And changing that won't affect any of your PHP code. The thing with file_put_contents is a completely separate issue. That error is telling you that /opt/lampp/htdocs/pages does not exist.
    It's also a red flag that you're using code to create this filesList.txt file, but I'm going to ignore it.
    Also, please tell me you're not running this as root. Use your user account - give it ownership of /opt/lampp/htdocs and everything inside it.
  24. requinix's post in The last MySQL having Windows XP (64bit) support was marked as the answer   
    This page lists their supported platforms. It doesn't go back far enough to list MySQL versions that existed around the time of Windows XP. Unsurprisingly.
    If you look at the Important Platform Support Updates, you'll see they killed XP support around 2014. Pull up the platforms page on archive.org around that timeframe, or a little later, and I bet you'll have an answer.
  25. requinix's post in php creating onclick function - "missing )" was marked as the answer   
    String needs to be in quotes.
    You've got one set on the outside for PHP, another set on the inside for the HTML attribute, and now you need a third set for the Javascript string.
    You have three options:
    // raw double quotes, but escaped because of the PHP quotes $out .="<tr class='align-middle custom-lc' onclick='triggerClientContextMenu($cId, \"$coName\")'>" // double quotes as HTML entities, which won't conflict with PHP's quotes $out .="<tr class='align-middle custom-lc' onclick='triggerClientContextMenu($cId, &quot;$coName&quot;)'>" // single quotes as HTML entities, which won't conflict with the HTML's quotes $out .="<tr class='align-middle custom-lc' onclick='triggerClientContextMenu($cId, &apos;$coName&apos;)'>" These three options may leave you open to problems if $coName contains apostrophes and you haven't protected yourself against that.
    A fourth option is to run $coName through json_encode and then htmlspecialchars with the ENT_QUOTES flag (and them in that order), after which you can put it directly into the "code" without manually adding quotes.
    But the fifth option is better: take a whole different approach to this by not using 1990s' web techniques like inline Javascript handlers...
×
×
  • 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.