-
Posts
1,698 -
Joined
-
Last visited
-
Days Won
53
Everything posted by maxxd
-
How to check when a form field is left blank
maxxd replied to SaranacLake's topic in PHP Coding Help
The snippet you posted is missing a closing parenthesis. Assuming that somehow didn't throw an error, the lack of curly braces means that the var_dump() is only run if the request method is $_POST, but the exit() is always run. -
How to check when a form field is left blank
maxxd replied to SaranacLake's topic in PHP Coding Help
<?php if ($_SERVER['REQUEST_METHOD']=='POST' var_dump($_POST); exit(); This snippet doesn't "definitely work". -
How can I optimize my PHP code for better performance
maxxd replied to djohnstone's topic in PHP Coding Help
AFAIR, if you were timing out you'd be seeing a 504 Bad Gateway error, so it's a problem with the form handling code. If you've turned on error reporting and verified it through phpinfo(), you should be seeing the problem in the browser. Make sure you've enabled 'display_startup_errors' in the same php.ini - your script may be crashing before it even gets to your code. -
The way WordPress (and most of the internet, nowadays) works is that it uses a pattern called a front controller. Every request is routed through the 'index.php' file, so https://mydomain.uk is a page, and everything after the question mark is a URL variable. For instance, 's' is specifically what WordPress looks for to know it's being asked to search for something. Click the links in my earlier post and you'll have your answer - use is_logged_in in the template file and the template_redirect action hook. If you don't know how to do that, start here.
-
While I agree with requinix in theory, it also kinda depends on the business logic. Laravel allows for multiple database connections, and with cloud services like AWS you can redirect to specific servers based on subdomain (as well as path and a variety of other criteria). So, it's possible that companya.project.com can be hosted on a completely separate server than companyb.project.com. If you're expecting each company's data set to get very large it may be best to separate the databases based on those subdomains and either use separate connections in Laravel config or use CI/CD variables to control the actual database credentials via the .env file.
-
The answer to both of your questions is is_user_logged_in(). For the first situation, check it in your template before outputting the div or class, and in the second situation check the value using the template_rediect action. Oh, and "uk/?s=fred&post_type=product" is a page (post, in WP's case) - it's '/uk/' with URL parameters 's' and 'product'.
-
It's not as succinct as one could hope, but this should work. let vals = []; let fields = document.getElementsByName('roles[]'); for(let item of fields){ vals.push(item.value); } console.log(JSON.stringify(vals)); I had thought the forEach() method would work, but had trouble with that, and of course the return is a NodeList instead of a true Array so using map() wouldn't work either.
-
OK - you know what you want to do, which is good. What have you done so far to get there? What's the question?
-
How can I limit the number of times the for each loop will run?
maxxd replied to guymclarenza's topic in PHP Coding Help
var_dump $url and see what it actually is. -
How can I limit the number of times the for each loop will run?
maxxd replied to guymclarenza's topic in PHP Coding Help
You're returning $query->rowCount() != 0 before you do anything with the results of the query. -
Not receiving email after submitting form
maxxd replied to warren_thieras's topic in PHP Coding Help
Also, some mail services will mark a message as spam or not deliver it if the 'from' address doesn't match the actual domain from which the email is sent. You set from to the email of the user filling out the form - probably not going to match your domain. If your mail actually isn't going anywhere or is ending up in the spam folder, try changing the 'from' header to 'contact@jtconfirmation.co.za'. -
There are plenty of sites that will tell you if the username you're choosing is unavailable - I'm pretty sure github does this, but it's been a while so I could be wrong. While I agree that if you're making the user hit submit with both password and username, don't tell the user whether it's the username or password that's incorrect; however if your goal is to let the user know before they hit send, you're gonna have to do it. As for usernames of 'PHP' or 'admin', you shouldn't be using that alone to determine capability to begin with. Hopefully your system has not only password protection, but roles to disallow major system changes from all but specific users. So in the grand scheme of things, it doesn't really matter what the user name is as long as it's not 'Little Bobby Tables' and/or you use prepared statements to protect against SQL-injection and avoid using exec(). Use AJAX to check for the username after it's been entered and let the user know if it's not available. Just make sure the passwords are strong - there are some libraries and information available if you Google.
-
I remember at one point that composer 2 wasn't compatible in some ways with earlier versions of php, but that doesn't appear to be the case at this point. However, if you absolutely need different versions of composer and want to do it easily, consider using docker. Re-reading this thread I'm not sure the exact use case (it's late after a long day, so I may have just missed it) but it certainly seems like you're making things more complicated than they need to be.
-
Use .htaccess and mod_rewrite - most if not all modern frameworks do it this way, and it gives you the pretty urls you're looking for. As you move forward with redoing your main site (if you continue to eschew an established full framework) you might want to check out Slim for your routing and dependency injection - I've heard good things about it, and the small amount of playing I've done with it I found enjoyable. I'm sure others with more direct experience can give you better and more advice on it.
-
As far as I can tell, it's good. Nice thing for me is BitBucket offers unlimited free private repositories with up to (I believe - it's been a while since I checked) 5 contributors per repository. So for a small team or independent developer with friends, totally free forever. And SourceTree is free no matter what - you can use as many different accounts on as many different repository hosts as you want - BitBucket, GitHub, GitLabs, or Azure. Good lord, I should get a commission. Of course, a commission on free is pretty much what I'm already getting, so there ya' go.
-
I use BitBucket private repos and SourceTree for git. It's totally point-and click and SourceTree is mostly stable on both Windows and Mac.
-
Need help with shortcodes that take a specific URL or input
maxxd replied to gabby25's topic in PHP Coding Help
Beyond that, your code makes almost no semantic sense. $class indicates the value is a class name, but you're using it in an href attribute. $url should contain, well, a URL. You're using it in a href tel attribute (as requinix points out, twice). Make maintenance easier on yourself and try make variable names make some sort of sense given the data they're expected to contain. -
By using the $_POST array like you do in the opening conditional. None of the variables you're using in the body string are defined when you try to use them.
-
If your PHP is also about 8 years old, it's going to need to be redone anyway, and probably sooner rather than later. I'd recommend pushing the site live when the e-commerce part is done, tested, and validated/verified. Then use a strangler fig pattern to iterate on the code, refactoring and replacing bits and pieces as you go. You can make changes to the HTML (PHP output, whatever) and CSS without touching the PHP. You could even start ripping out procedural code and converting to a more modern, extendable and maintainable code-base.
-
If your code is well thought out to begin with, making it responsive is CSS-based and shouldn't be that big a deal in the grand scheme of things; in other words, it shouldn't touch your php much or at all. It may require some rethink on your html, but even then that should be pretty minimal. If you've got a ton of inline styles well, that's a different story, but you'll eventually have to redo the site to fix that anyway... So basically, as long as the functionality is complete and tested, push to production now and start refactoring right after that.
-
Wordpress can handle custom tables, but it doesn't like it. If you're using ACF you can create arrays of data - honestly, even when I was dealing with WP daily I never used ACF, but I knew a lot of people that did. I think it's called a 'repeater' - check this: https://www.advancedcustomfields.com/resources/code-examples/. Doing this will negate the need to append a number to the variable name, and allows you to use count() to do what you're looking to do. It also allows you to not loop exactly five times regardless the amount of data present, and to track a grave with more than 5 bodies.
-
Moving some PHP to the backend without a button press or anything
maxxd replied to JoshEir's topic in PHP Coding Help
In my experience, VSCode is not at all buggy; I've used PHPStorm and - personally - didn't like the project setup aspect of things. That having been said, I have to say that setting up a debugger is much easier with PHPStorm than VSCode, and all of my co-workers use PHPStorm and love it. So honestly, check out some plugins, give both a fair shake, and use what helps you get the work done. As for the code using ajax on page load, it kinda depends. Is this a page that you're gathering analytics or is it reliant on search engine rankings? If so, you're probably going to want to have content available when the page loads. If it's part of an SPA after the user has logged in, then you can do a fetch on page load. Or you can server-side render the initial page content, then use ajax or fetch to update and/or change that data depending on the user action. -
I'd use CSS grid in this case.
-
Moved hosters PHP was 5.x now 7.x PHP scripts no longer work.
maxxd replied to Nax's topic in PHP Coding Help
All the mysql_* functions were removed in 7.0. You'll need to rewrite the script entirely using either mysqli_* or PDO (recommended) in order for this to work. -
I've been coding PHP for about 20 years now - version 4 was just about to come out when I started. Most of that time was professional (I was lucky enough to have a job that paid me to learn while I worked at first). To this day, I learn something new every day, either while taking on a problem at work or coming here. Don't expect to be able to put a timer on when you "know" php. Get proficient with the language but more importantly understand programming. If you've committed to coding, read "The Pragmatic Programmer" by Andy Hunt and Dave Thomas, and "Design Patterns" by the Gang of Four. For a php specific viewpoint, check out "PHP Objects, Patterns, and Practices" by Matt Zandstra. There are other resources I'm sure more will chime in with, but those are three that I go back to regularly. There are online sources that are very good, but there are also online resources that are very bad, and it's often difficult to tell which is which. While you're doing tutorials, check in here - this is a great place to get good advice from seasoned professionals.