-
Posts
15,227 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
1. The 500 error would be due to a syntax error. I think your indentation in that $headers array is wrong - like it has non-breaking spaces instead of regular spaces. You may have copied this code from somewhere? Delete the leading spaces and type them out yourself. 2. The list of headers should only contain the Authorization - not the GET because that's not a header, and like I said not the Content-Type either (I think their docs meant to use an Accept...) 3. This is a GET request. It does not POST anything so there shouldn't be any "POST" options. 4. You're going to want CURLOPT_RETURNTRANSFER at some point later. Without, what the API returns will go to your browser, which is handy for the moment but not what you'll need. The other problem is the URL. You're supposed to put a value in for that ":survey_id". Then add that path to the api.getfeedback.com you have below and put the whole thing in for the CURLOPT_URL. It's the same value that you would put into your browser to test out the API (if not for the fact that the authentication wouldn't work). And please, don't post your Bearer token again. Protect it like it were your bank account number.
-
Sending a Content-Type with a GET request is incorrect so that's not right. And I'm not sure why you're reading books on JSON when your issues are with cURL and PHP. Here is the starting point of the documentation for how to use cURL in PHP. Check a couple of the examples, and Google, for the basic way to use it. It's pretty simple for a request like the one you've shown. What you'd need to do special is add a custom Authorization header to the request. That's done through curl_setopt() and one of the options in there. Write some code, give it a try, and see how things go. If you have problems then post what you've written and describe what's happening when you try it.
-
Why can't I access the fonts directory from PHP?
requinix replied to SLSCoder's topic in PHP Coding Help
You can, but it depends on configuration. Or a lack of, such as for the open_basedir PHP setting that would restrict your code from doing anything outside of a specific set of directories if it had been set. I don't know where your PHP logs are. Start looking at /var/log. -
Why can't I access the fonts directory from PHP?
requinix replied to SLSCoder's topic in PHP Coding Help
Also, take a look at your PHP error logs, in case there's anything in there that might be relevant to this issue... And by the way, even if this isn't shared hosting and you own the box, if you need the Verdana font then just bundle it into your application's codebase. Far more reliable than making sure you have fonts installed on what should be a headless box. -
Subracting a number from decimal value in mysql
requinix replied to PNewCode's topic in PHP Coding Help
DECIMAL(65,0) means it can store a number with 65 digits and 0 after the decimal point. -
Sure: upgrade to PHP 8 and see what it complains about. Not on the real site, of course, but in some development version of it. That's really the most effective method. I don't know what "tags" are, but the online documentation has migration guides. Go through each guide in sequence; if you want to upgrade to latest, which is 8.2, then you need the 7.3->7.4 and 7.4->8.0 and 8.0->8.1 and 8.1->8.2 guides.
-
-
how to read body content of a chucked CSV file sent to me
requinix replied to grjoseph's topic in PHP Coding Help
Then let's go back to the beginning: What did the "request catcher" capture? What is your current PHP code? -
how to read body content of a chucked CSV file sent to me
requinix replied to grjoseph's topic in PHP Coding Help
Where you are getting "upfile" from? I don't see that anywhere in the sample request you showed. The actual name was content-disposition: form-data; name="file"; filename="dip-01GQJAYVE75QE6QE1J1P3F892D.csv" "file" -
how to read body content of a chucked CSV file sent to me
requinix replied to grjoseph's topic in PHP Coding Help
That looks like a regular ol' file upload. -
Each button needs to know which result it's supposed to delete. Since you're doing this with AJAX you have a lot of flexibility in how to go about it, but my preferred is a data attribute. <button data-deletes-record="(id goes here)">Delete</button> With jQuery, you can then wait for a click event on a button with that attribute, $("#allRecords").on("click", "button[data-deletes-record]", function() { Inside that you can grab the ID with .attr() or .data() and then pass it through AJAX...
-
If you have to urldecode a query parameter yourself then you are doing something wrong.
-
You already know the answer to that: some point before you end up with 116 functions in a 2600+ line file. As for where "before" is, that's tricky. Because despite what many others will say, sometimes having complicated things contained in one single place makes them easier to understand than if they had their components spread out across multiple locations - but having that as an exception to the rule also lends itself to being an excuse to ignore the rule. The simplest approach is what I hinted at: separate by category, or purpose. With 116 functions there are going to be a much smaller number, perhaps a dozen, of groupings. Like notes functions, and activity functions. Even if you only had one "createNote" note function, the fact that it's a different subject matter than activities warrants having it in its own place. The other answer is that good code design won't let you create massive utility classes to begin with - no offense. Following principles like SOLID (its "single-responsibility principle" is what that whole categorization thing is essentially about) or DRY will naturally encourage you to break things up as a side-effect.
-
Then the first step I would recommend towards improving the code is to split the functions into classes for categories. Like one for notes that has createNote. And another for activities that has markActivityCompleted. And unless you need actual instances of these classes, you might as well switch to purely static methods. $activity_id = NotesFunctions::createNote($x[1],$notesDetails); ActivityFunctions::markActivityCompleted($activity_id); That alleviates the short-term problem of where you put code. After that you could switch more easily to an actual OOP design, where you have a class for notes and a class for activities, and you use each instance of the class like it was a particular note/activity. As a simple example, $note = Note::create($x[1], $notesDetails); // $note is an instance of Note /* class Note { public function __construct($note_data) { ... } public static function create($whatever_x_is, $details) { ... return new Note($note_data); } } */ $activity = $note->getActivity(); // $activity is an instance of Activity /* class Note { private $activity_id; public function getActivity() { return Activity::get($this->activity_id); } } class Activity { public function __construct($activity_data) { ... } public static function get($id) { ... return new Activity($activity_data); } } */ $activity->markCompleted(); /* class Activity { public function markCompleted() { ... } } */ You can bridge the gap between those two steps by keeping NotesFunctions and ActivityFunctions, but changing their methods to use these new classes. class NotesFunctions { public static function createNote($whatever_x_is, $details) { $note = Note::create($whatever_x_is, $details); return $note->getActivityId(); // getActivityId is a temporary method created so you can return an ID from here } } class ActivityFunctions { public static function markActivityCompleted($id) { $activity = Activity::get($id); $activity->markCompleted(); } }
-
Then rawurlencode was the more appropriate one, however http_build_query is nicer so use that. <a href="http://xxx.com/tools/members_by_age_rpt.php?<?= http_build_query(["range" => $variable]) ?>">
-
sigh Your username is wrong, and/or your password is wrong, and/or the database name is wrong, and/or that's all correct except those accounts don't actually have the access they need granted yet.
-
This is the error. Access denied for user 'avjopazg_com'@'localhost' to database 'avjopazg_com' Do you know what that means?
-
When you say helper "functions", do you mean actual functions or do you mean classes and class methods? How about a sample of what we're talking about?
-
You've received an error. What have you tried to do about it? Do you understand what the error means?
-
There is no "$data" being used in "if (curl_exec($curl))". Take another look. Are you trying to edit someone's WP plugin? Have you checked for a more recent version of it?