-
Posts
1,698 -
Joined
-
Last visited
-
Days Won
53
Everything posted by maxxd
-
So, as @benanamen pointed out above, the code you posted is incomplete and "I keep getting errors when I try to change it" isn't nearly specific enough to help us to help you debug. In addition, Google Chrome developer tools won't cause errors - they will report them (depending on the error type); depending on which tab you're on, those errors may be server-side (php) or they may be client-side(JavaScript). You'll have to tell us what the error is and which tab in the tools is reporting it. As far as the comment about prepared statements, again benanamen is correct - check out these links: https://www.php.net/manual/en/pdo.prepared-statements.php https://www.php.net/manual/en/pdo.prepare.php
-
Display another file on button click in div on same page
maxxd replied to pfoster77's topic in PHP Coding Help
You're gonna need AJAX - there are a few different ways nowadays to go about it. -
Put it before the first line. If it's throwing errors, post them here.
-
With Ajax, opening a PHP function on the same page without JQuery.
maxxd replied to JoshEir's topic in PHP Coding Help
The bigger question at this point is what is the actual problem you're trying to solve? Given what you've just posted, you'd be far better off simply injecting $descriptionVar into the markup on the server. -
With Ajax, opening a PHP function on the same page without JQuery.
maxxd replied to JoshEir's topic in PHP Coding Help
There's no AJAX in anything you just posted. I'm also assuming that's an example because there's nothing there that JavaScript alone couldn't handle on its own. The PHP will parse the call to myphpfunction() on the server before the page gets sent to the browser - the JavaScript will be this: <script type="text/javascript"> alert("The sum is: 360"); </script> If that's all you need, that's fine. If you need to call myphpfunction() with different values based on a user selection and you don't want to reload the entire page, you're going to have to use JavaScript and AJAX. -
With Ajax, opening a PHP function on the same page without JQuery.
maxxd replied to JoshEir's topic in PHP Coding Help
You don't need jQuery to run AJAX, you just need JavaScript. So, either go modern with fetch or use XMLHttpRequest (or ActiveXObject). If you want to make multiple AJAX calls from the same page, nothing's stopping you - pick a trigger and call a different PHP target for the request. If you want to get tricky, pass an 'action' parameter to your PHP and decide the action to run based on that - let resp = fetch(url, { method: 'get', body: JSON.stringify({ 'action': 'doSomething', 'data': ['data','more','etc'] }) }); function doSomething(){ switch($_GET['action']){ case 'doSomething': doSomething($_GET['data']); break; case 'doSomethingElse': doSomethingElse($_GET['data']); break; } } (not tested code, just a basic idea) -
Find value inside foreach and use if statment on that one
maxxd replied to Silverman's topic in PHP Coding Help
And now I'm confused... -
how can i fetch data from laravel-mysql using ajax?
maxxd replied to mahenda's topic in PHP Coding Help
Assuming your employee table includes a columns named 'name' and one named 'intro', and your department table includes the columns 'name' and 'desc', everything should be working. What does 'Nothing work' mean, exactly? What are you seeing now? -
how can i fetch data from laravel-mysql using ajax?
maxxd replied to mahenda's topic in PHP Coding Help
Your PHP is returning an array including 'employee' and 'department'. Your JavaScript is looking for 'name' (twice, so you might want to rethink that), 'intro', and 'desc'. -
Session Start - Headers already sent. What am I doing wrong?
maxxd replied to MAtkins's topic in PHP Coding Help
There's output somewhere before your opening PHP tag. Make sure you don't have a space or carriage return, check other included files, and check your file encoding. -
Hi all. Does anyone use Localstack to for local AWS development? I'm currently developing on a system that uses numerous AWS SQS queues, AWS ElasticSearch, AWS Redis, and many, many S3 buckets with about three dozen PHP-based micro-services; I've built a local development environment consisting of containers using several Docker images, one of which mocks AWS using a Localstack image. This works, for the most part, but I find that the Localstack instance just ... stops working. It - after a random amount of time, and intermittently if more often than not - won't process any of the queues that the system uses, or will drop bucket contents despite being set up for persistence (the `DATA_DIR` objective is set to `/tmp/localstack/data` as instructed in the README). I get the impression that Localstack is fairly widely used for local AWS development, so I have to assume if this was a normal situation I'd've found it in my searching, but so far it doesn't seem to be a big deal. I'll post the docker-compose file here if it helps, but does anyone have any experience with a similar situation and feel like sharing tips? Did it work, did it not, do I need to convince my company to pay for the pro version, do I need to do a modified rain dance, etc? As always, thanks in advance for any thoughts or advice.
-
Interesting - don't know how I've managed to avoid that issue. Thanks for the info!
-
I have, and it was a genuine question. I guess I've just been lucky enough to have never come across a situation where the distinction has bitten me in the butt or where I've noticed, in all honesty.
-
I don't mean to be rude, but you're going to have to do some work on your own, here. Again, I'm not writing this for you - what's the value of $lastCall? Echo it out, explore what the code's doing. If nothing else has changed in the code you posted, it doesn't matter because you don't actually use the code that I gave you.
-
I'm sure it does, because you copied and pasted my code and then didn't use it. If you had error reporting turned on you'd be getting an error about the fact that $money doesn't actually exist. You may not know how to code, but you can obviously read. Apply some though to what you're seeing here and adapt the code that you've got with the code you've been given.
-
This is entirely untested, but using the snippet of code you posted first and the statement that you've got a running Redis server, try this: function doSomeStuff(){ try{ $redis = new Redis(); }catch(RedisException $e){ die('Could not connect to Redis host'); } if(!$redis->connect('127.0.0.1', 6379)){ die('Redis connection failed'); } $lastCall = $redis->get('API::CALL::LAST'); if(empty($lastCall) || microtime() - $lastCall > (5 * 60 * 1000)){ $myData = file_get_contents(''); $myObject = json_decode($myData); if(!is_null($myObject)){ $myObjectMap = $myObject->result; $redis->set('API::CALL::LAST', microtime()); return $myObjectMap; } } return false; } $stuff = doSomeStuff();
-
Which is why I recommended Redis to begin with. Honestly, I kinda assumed it was a standard default in host/VPN setups (which may tell you how out of touch I am with devOps and server admin).
-
Here are a couple links on using Redis - it's super simple. https://redislabs.com/lp/php-redis/ and https://github.com/phpredis/phpredis. Long story short, I'm not going to write your code for you. The point of this board is to help people when they get stuck with the code they're writing - I feel I've done that in this case. Take what you know and what I suggested and try to write it. If you have problems then, post the code you've written and we can all take another look. But you're not going to learn anything if I write the code for you.
-
Pseudocode: $lastCall = Redis::get('API::CALL::LAST'); if(empty($lastCall) || microtime() - $lastCall > (5 * 60 * 1000)){ $this->apiReturn = makeApiCall(); Redis::set('API::CALL::LAST', microtime()); return $this->apiReturn; } return $this->apiReturn;
-
I'd probably store the last time the API call was run in a Redis key, then check against it before running the next call. Honestly I'm not sure that setting a 5 minute TTL on a Redis key will delete the key after 5 minutes (I think it will, but I'm not completely sure and if it's important you shouldn't mess about with it), so it's probably safer to just create a key and update it every time the API call is made.
-
Every time you make the call, store the time. Then compare it before you make the next call - if it's been less than 5 minutes, use the existing data. Otherwise make the call again. Or you can use Redis with a 5 minute TTL - if the index exists, use it. If not, refresh it.
-
That kinda depends on the third-party's API. If you make the call in Postman does it take a minute? Honestly, the fact that the load time increases each time you submit the page makes me think it's the PHP, but I haven't looked that closely at your code.
-
Again, ajax has absolutely nothing to do with curl. If you're missing information between pages 1 and 4, you need to set the information in either a session or cookie variable, or pass it between the pages in another way. Of use local storage in JavaScript. You also mention 'simulating' a click to pages2, 3, and 4 - I'm not sure what you mean by that. Do you physically click a link or button on a page that sends you to a new page, or does something else happen? On a side note - @kicken, I don't recall having heard of fiddler before. I'm gonna explore that 'cause it looks pretty cool; thanks for the heads-up!
-
Please post the code in question here (and please use the '<>' button to format your code), as well as explaining exactly what '4 pages deep' means. If I'm understanding correctly, there's nothing inherently special about a 'https://tld.com/page1/page2/page3/page4' curl call that would cause an ajax error. And now that I type that, ajax and curl are completely different things so perhaps posting the JavaScript ajax code along with the relevant PHP would help.