Jump to content

maxxd

Gurus
  • Content Count

    1,047
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by maxxd

  1. If it's set up in the image you could use exif_read_data() to grab comment metadata and output that as the caption.
  2. I totally get that, but there's really not a more elegant way to handle this situation that I can think of off the top of my head - maybe someone else can pop in with a suggestion.
  3. In the second code block, you're only running the readdir() once, so as long as it's not false on the initial run, it never will be.
  4. I can't see where $ranges is defined, so once you define $two_letter_country_code you may have another undefined variable error unless it's defined in "ip_files/".$numbers[0].".php".
  5. When I asked you to post the code, I meant for you to post the code that's actually being run. You mention a 'first' script that you don't show us, and then talk about what doesn't happen when you "combine" that script with what you do show. How are you combining the scripts? What does the resulting script look like? Right now you're asking us to tell you why your shower isn't working by telling us you have a bathroom.
  6. Sorry - bit confused here. Are you saying that if you've already submitted the form and then you run JavaScript replaceState it doesn't resubmit your data? I'm sure someone will correct me if I'm mistaken, but I believe that replaceState() won't actually redirect or refresh your browser - it just tells the browser history object where it thinks it's been or where it thinks it currently is. If you're trying to actually reload the current page, maybe window.location.reload()?
  7. You're going to have to post your code. PHP inside HTML may not be the best idea in the world, but it works pretty flawlessly assuming everything is done correctly. My bet is that if your JavaScript stopped working, something didn't get named what it is later called and the error is pretty standard once you see it. As far as which should be done first (PHP/HTML/JavaScript), if you're determined to combine PHP and HTML, put the PHP code first. Deal with any form handling, collate the page variables, and deal with the system business logic, then render the HTML display. Keep your JavaScript entirely separate from all of that so that you can minimize and uglify it via webpack or gulp. This will at least get you a step or two closer to true separation of concerns, and that'll save you refactoring time in the future. Oh - and a form action is "run" when the form is submitted. Nothing's actually run as such, the browser redirects to the page named in the form's action property and passes the data from the form to the page via either $_GET or $_POST, depending on the method attribute of the forms.
  8. OK - I assume the 'installation & loading' section of the readme got you sorted? Ask any questions you've got on it here, but I can almost guarantee that you'll have a much, much better experience using PHPMailer than you've had using PHP's native mail() function.
  9. Or $_POST or $_GET as well as the WHERE clause; the important part here is that you're gonna need a WHERE clause in your SQL statement.
  10. OK - this is not a session problem, it's a problem of not understanding variables or SQL. Your SQL statement is currently looping through every record in the table and saying 'update the current record if the ID value of the current record is equal to the ID of the current record'. Which, as Barand pointed out, will always be true. So if you're wanting to only update one specific record at a time, you'll have to get the user_id of the specific record you want to update and then assign that value to a php variable (which begins with a dollar sign), which you will then use as the value of `user_id` in the WHERE clause.
  11. I recommend reading this page - https://www.php.net/manual/en/language.variables.basics.php
  12. You set $_SESSION['eqname'] before your inner-most if statement. There are no else clauses for the other two if statements, so I assume that's the one you're talking about. For now, don't worry about running the second query or redirecting the user. Just do this until you get the results you expect: echo "<p>{$stmt->num_rows()}</p>"; if($stmt->num_rows() > 0){ die('rows were found'); }else{ die('nothing there'); }
  13. I could be completely wrong, but I think the official Docker PHP image is built on Ubuntu with Apache2x. So it theoretically should be almost as simple as `docker-up` And @dalecosp, You're kinda killing me with that - I miss Virtualbox and Vagrant by now. Docker is great, but really fiddly and docker-compose files don't make as much sense to me as Vagrantfiles did...
  14. If you've got some time, you could use Docker or install WSL. Otherwise, you'll have to set up another version of your production server and blow things up there instead of the live site.
  15. // $id may or may not exist, doesn't matter for ($i = 0; $i <= 5; $i++) { if (isset($_REQUEST["element_id_$i"])) { // Now you're checking _any_ input for anything called element_id_{0-5} and assigning it to the session variable. // $id is still potentially undefined $_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"]; // OK, so now $id is a string or integer or float or whatever (validate your input, please) $id = $_SESSION["element_id_$i"]; // $_SESSION['element_id'] is an array because you're using array_push array_push($_SESSION["element_id"], $id); } // And now $id is an array because you're overwriting the value you've already put in there // Also, at this point if $_REQUEST['element_id_{0-5}'] _isn't_ set, $_SESSION['element_id'] should // not exist and you'll get an error $id = $_SESSION["element_id"]; } So $id is an array. You can use variables as array keys, but the value of those variables has to be a string or integer - you can't use an array as an index in another array.
  16. $cart_items[$id] = $quantity; and $cart_items = array($id => $quantity); are two very different things. What's the value of $id?
  17. You can use variables as the index when you create an associative array. Considering that, and as you already have the variables that contain the id and quantity, the solution should be pretty obvious...
  18. Comment when and where it's necessary. When it comes to methods, I'm a fan of always writing documentation but at least document the parameters, regardless the scope of the method - I've heard people say it's only important to document the public API of a class. This is utter bullshit. However, when it comes to initial documentation for a class if it does something weird, then yeah - document that sucker. For instance, your Formatter class seems simple enough - it formats a thing. However, if you're not using namespaces and your system formats both HTML and JSON, but Formatter only deals with JSON then document that. I'd argue you should use namespaces or rethink your class naming scheme, but sometimes you come into legacy code and have to do what you have to do.
  19. Yeah, I got nothin'. The only thing I know about cars is where the gas goes and where to take it when something sounds weird. Again, I know very little but serial numbers should be specific to each engine, correct? So that doesn't seem like an issue in any way. Wut? At any rate, I would think if you're trying to keep track of modifications to cars and car parts the best bet would be a car table, a parts table, and a modifications table with a compound foreign key of car_id and part_id. That _theoretically_ should give you a time-specific snapshot of parts and mods per car.
  20. I strongly recommend against that. As one who will drive a car until it falls apart completely, I can see a situation where a single car can could have multiple motors, the defining data of which could be repeated. [Disclaimer: I know nothing about cars or engines, so please don't take my example as a real-world situation] If my Honda Element has a Hemi when I buy it, but I drive it to the point that the hemi dies and I put a V8 in there, cool with the unique limiter. However, if I then drive the same Element until the V8 dies and I decide to put different hemi in there, well then there's a problem. Play it safe for the future - Barand's junction table is the way to go; even if you don't use it as a many-to-many junction point right now, you may have to later.
  21. I'm sorry, but what? I'm not trying to be an ass, but take a breath, step back, and describe what you want to do one simple step at a time. Write out the pseudo-code, then post it here.
  22. And thankfully, those versions are mostly dead at this point. Or so I choose to believe, anyway...
  23. The two chunks of code you've posted are completely unrelated. I don't know what mf_get_option('login_reg_popup') should or could return, but if it's falsey it'll set the action parameter of your checkout button link to the login page. If it's truthy it'll set it to ... nothing, really. Your second chunk of code redirects everything to $_SERVER['HTTP_REFERRER'] (which I'm pretty sure is a massive security issue, not to mention the fact that it applies to everything). Then, later - assuming the code gets there after the ill-advised redirect - it sets up an action handler for template_redirect that again calls the wpse_131562_redirect() function on every page load. Assuming mf_get_option('login_reg_popup') returns false if the user is not logged in, I think what you want to do is replace the '#' in your first code chunk with wc_get_checkout_url().
×
×
  • 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.