Jump to content

maxxd

Gurus
  • Posts

    1,678
  • Joined

  • Last visited

  • Days Won

    52

Posts posted by maxxd

  1. I don't see where you've posted your form code in the thread - just to confirm that you've got all the data you think you have, put the following right after the `if($_SERVER['REQUEST_METHOD'] == 'POST') {` line:

    die('<pre>'.var_export($_POST, true).'</pre>');

    Then check to make sure there's keys for email, subject, and msg in the $_POST array.

  2. jodunno is correct - you need some sort of persistence to make this work. The web is an inherently stateless medium, which means that by default any work a visitor does on a page (start a timer, set a variable, write a book, etc) is gone as soon as they navigate away from or refresh the page - nothing on that page remembers what was done on it before the refresh. I don't see any php in either of your code samples so I assume you'd rather stay in javascript. Look at sessions (https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) because it's gonna be the easiest way to do what you want. You'll save the expiration time to a session variable when the timer is started, and on every page load check to see if that session variable is set. If it is, check to see if it's expired - if it's set but not expired, don't re-initialize the countdown. If it's not set, initialize the countdown. If it's set but expired, tell the user that.

  3. Yeah, I had a fairly robust component library before I ended up at jobs that used or were moving to Laravel - it's a good way to go whether you're using a framework or not. And it's always possible to use packages as bits and pieces in your own home-grown PHP code. Symfony is modular and it's easy to use composer install to use the packages you're interested in. Same with some of the Laravel packages, though I think that's probably more difficult as there's a lot of inheritance in Laravel and that could cause some issues.

  4. Using a framework like Laravel or CodeIgniter will cut down on the boilerplate code you're creating, but you still need to code. So while in vanilla PHP you'll write the DB connection script once then include it in an object and use that to persist the data to the database, with a framework you'll still be doing the same basic thing. The only difference is that someone has already written the DB connection for you - you still need to assign the values to the columns and tell the framework to save the record.

    Where frameworks really come in handy is convenience and convention. Most frameworks that I know of these days are OOP-based so they're using either PDO or MySQLi behind the scenes, and most will parse the insert/select queries you pass to them into prepared statements. This is obviously convenient because you don't have to specifically write that code. It's still very possible to screw it up and bypass it, but you kinda have to try to do it. The convention part is less obvious and arguably less ... good, I guess. Frameworks have their own dialect of PHP and it's not always easy to learn or keep track of. On top of that, there's a lot of magic some frameworks (cough cough ... Laravel) inject that can make it difficult at times to reason about the path the data takes through your system. Once you learn the dialect you can get things done quite quickly, but sometimes that dialect changes in an update and that can make life difficult. Again, Laravel was most notorious for just changing major things in minor updates but they've lately stopped doing that and the upgrade path is much easier and safer than it was just a few years ago. That having been said, some of the major updates can still be rather jarring.

    I'm not a blind fan of Laravel, but I've been using it for about 5 years now almost exclusively and I've gotten used to it and find it enjoyable for the most part. It offers a lot by default and once you get used to the syntax, service layer, and some of the other magic involved it's possible to get a lot done quickly. I've also worked with and enjoyed CodeIgniter 4 but it offers less built-in functionality and magic out of the box (or at least it did at the time). Yii sucks in my experience and opinion, but YMMV.

    Oh, and obviously there's a learning curve with a framework - regardless of which you choose.

  5. Making the transition from procedural to object-oriented can be daunting at first, but it's worth it in the long run. The code (when written correctly) ends up being much easier to parse and reason about and - as mac_gyver alluded to with the comment about exceptions - much safer and more stable. Not only that it's the way the core is headed, and most if not all frameworks are object-oriented by this point.

    There are a ton of resources online, and of course you've got a great resource in this forum.

  6. XHTML was a thing quite some time ago. Modern HTML has the semantic benefits that XHTML (as I understood it at the time) claimed to have, while not being as strict in terms of some of the usage. You'll also find modern HTML referred to as HTML5, though honestly these days I'm not sure if the version number even means anything anymore.

    • Like 1
  7. In addition to everything requinix and mac_gyver have mentioned, you have several different <form></form> elements in your HTML - this is incorrect. There should be one form that encompasses all the input fields in your form. The reason you're getting the success message every time is that the form element that surrounds the submit button contains only the submit button - the Email field is in a different form (I'm assuming - your formatting got weird and hard to follow). Add the following right before the `<?php if(isset($_POST['Email']) {` line in application.php:

    <pre><?php var_export($_POST, true); ?></pre>

     

  8. Try dumping out $data['products'] like so:

    dd($data['products']);

    Make sure there's actually anything there to loop through. You can also add try/catch blocks around the orderProduct and product creation and log any exceptions you catch.

  9. Just a point of clarification, in this case json_decode is returning an object not an array. To access any of the values in the object, call the property key. For instance, to loop through the players you'd do this:

    foreach($obj->event_match_details as $detail){
    	echo "{$detail->playerfirstname} {$detail->playerlastname}"
    }

     

  10. I hope this makes sense - it's how I thought about it a millennia ago when I was learning php - you can mix php and html, but you can't combine them.

    In other words, as Barand said above, if you want to output html without using the print or echo functionality of php, you need to exit php mode and enter the browser's default mode of html output by using the '?>' php closing tag. By the same regard, if you intend to inject php into your html you need to specifically enter php mode using the '<?php' opening tag.

    There are obviously exceptions to this (certain templating languages, etc.) but these are things to think about later on - right now don't worry about it. Just make sure all of the php code you're executing within html is contained in the '<?php ?>' tags.

  11. First and foremost, don't run the query in a loop. Chances are you can use a join to get a full dataset before you begin your loop. The other benefit of doing this is that your data will more than likely present itself in a way that makes what you're trying to do easier. Can't help you with how to do that as we don't have all the code and what we do have is clearly not the actual code (there's no $sqlb2 for you to loop over in what you've posted).

  12. Does that mean that you've made sure you're using prepared statements, nonces for your CSRF, and proper XSS request headers or do you mean you feel fine altering user input because what you have looks like it's working as it is?

  13. The image tag is the main element in this situation - it's wrapped in a picture tag (the container), and the src elements can be thought of in the same way that media queries are in css. You need to have the img tag in the picture element to actually display the image source as defined by the src elements depending on their media attribute.

    Basically, in your situation the <img> tag is the only actual element in the structure. The rest of it is conditionals.

×
×
  • 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.