-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Was that obfuscated code you're trying to unravel? Shouldn't you be modifying the original source?
-
Then what I said is true. And here's a link. Then might I suggest you try, I dunno, learning it?
-
Depends what the code is, but you're probably trying to use an index in $_GET or $_POST that hasn't been set and you probably should try to check that it's been set before using it.
-
If there aren't any other, larger, more important problems lurking then it's just a matter of putting quotes around array keys. Turn this $_POST[otsikko]into this $_POST["otsikko"] // or $_POST['otsikko']The file and line numbers in the error messages will point you to where the problems are.
-
Find your php.ini and set error_reporting = -1 display_errors = onThen restart your web server and run your script. Do you still get that error message? (I'm sure you will.) The message means you don't have the mysqli extension enabled. Are you sure that's what you're supposed to be using? Maybe you're using the mysql_* functions or PDO in the rest of your code?
-
You're shuffling the arrays in $_SESSION['data']. That is, you're shuffling "question" and "answer" and "type" around amongst themselves. You aren't actually shuffling the questions, answers, or types. You need to put each question+answer+type tuple into an array and put that array into the session as a unit. Then you can shuffle it. while ($row3 = mysql_fetch_array($result3)) { $_SESSION['data'][] = $row3; // as the key/values are identical } print $count . ". " . $_SESSION['data'][$count]['question'] . "<br>"; print $_SESSION['data'][$count]['answer']; print $_SESSION['data'][$count]['type'];
-
Alright, so the explanation of why: php.ini gets loaded before anything in the php.d directory. That means your extension=pdo_odbc.so was executed before any other extensions could be loaded, however it's required that you load the PDO extension before you load any PDO drivers. So PHP bailed. It then started reading stuff from php.d, including the parts where it was told to load pdo.so and pdo_odbc.so; those were in the right load order so it all worked and you still got your extension in the end. So the moral of the story is that if you have a php.d (or other similar directory) then that's where extension loading should be done - not the php.ini.
-
Define "a lot". 1. Generally not, unless you're using an obscene number of them (which I'm sure you're not). 2. Generally not, but it depends what you do with them. 3. See #2.
-
Post your code.
-
Having spent years trying to get others to understand that very idea, I've found a fairly simple way of convincing people to post solutions: what you do is
-
Sharing function within multiple unrelated classes?
requinix replied to RuleBritannia's topic in PHP Coding Help
I'd just make a global function for it. Don't believe the people who insist on making utility classes and such: PHP is not like Java or C# where you have no choice. [edit] Just by that description. If the values in these arrays are more than just mere numbers then there may be a more appropriate OOP solution (and I don't mean a utility class)... -
Sharing function within multiple unrelated classes?
requinix replied to RuleBritannia's topic in PHP Coding Help
What's the function and what do you use it for (if it's not obvious)? To the question, I don't actually know of any functions I'd reuse that don't clearly belong in a class... -
I'm sure not everything in there needs 0777 permissions. Isn't it just a couple directories or files?
-
Cleaning URLs, excluding certain URLs (login.php)
requinix replied to Lukeidiot's topic in Regex Help
Spending a couple minutes checking the documentation, it sounds like you can put that rule in a url.rewrite-if-not-file block. -
First a comment: please don't use the ->{} syntax when it's not necessary. It's valid, yes, but not really something that should be used often, and definitely not when there's a "normal" version that works. $wlocation = $parsed_json->current_observation->display_location->full;It's a bit hard to tell from that JSON (it's formatted oddly) but I think the array you want to loop over is tide->tide_summary. foreach ($parsed_json->tide->tide_summary as $summary) { print_r($summary); }To get a table... it depends how you want it to be outputted. What should the resultant HTML look like? Maybe with some sample data?
-
Here is a good place to start. Assuming you're using PHP 5.3 or later, first step is getting the SQLSRV extension from Microsoft. Not the mssql extension.
-
Begin doing what?
-
No it will not, and no there is no reasonable way to do that - besides making your code do it manually.
-
while($row = mysql_fetch_array($result)) $ruby=$row['ruby']; $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal'];If you don't use {}s on a loop then only the next statement will be executed in the loop. Like while($row = mysql_fetch_array($result)) { $ruby=$row['ruby']; } $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal'];After the loop $row will be false (it read everything) and you won't have any diamonds, emeralds, or crystals. In your case, forget the loop. There's only one row. $row = mysql_fetch_array($result); $ruby=$row['ruby']; $diamond=$row['diamond']; $emerald=$row['emerald']; $crystal=$row['crystal'];
-
Accessing object map holding updated data.
requinix replied to RuleBritannia's topic in PHP Coding Help
PHP isn't really suited to the idea of having a centralized bit of memory where you can stuff objects. Scalar values, like strings and numbers, are easier, but with objects it's a bit more complicated. Anyway, what's the harm of letting your code continue thinking the price is 22000? That was totally okay just seconds ago. So what if the change doesn't take effect immediately? Remember that most scripts take a fraction of a second to run, so it's not like you're holding the object in memory for an extended period. With that said, the #1 time changes like that do matter are when you're editing the object in multiple places (as opposed to editing in just one and viewing in all the others). Don't want one person's changes to be lost, of course. However you can solve that with a) Modification timestamps, which will tell you if the object changed since you loaded it, b) Doing an UPDATE with the condition that the current values match what you have in memory, like UPDATE table SET field1 = "new value 1", field2 = "new value 2" WHERE id = 123 AND field1 = "old value 1" AND field2 = "old value 2"(after which you check to see if it updated anything) c) Versioning, which can greatly complicate the system but has distinct advantages you might want to make use of anyways -
Send user back to same page without action set
requinix replied to Cyonis's topic in PHP Coding Help
By the way, the thing I posted with substr() isn't quite right. Should be substr($_SERVER["REQUEST_URI"], 0, strcspn($_SERVER["REQUEST_URI"], "?")) -
It sounds like you should start learning PHP now and ask questions later, rather than ask questions now and learn later. Because the whole idea of learning is so that you don't have to ask questions Short version? You define the function somewhere* and call it at the point you want. Like if the function is function now() { return date("Y-m-d H:i:s"); }then you can call it as whatever HTML you want here <?php echo now(); // echo to output whatever value now() returned ?> whatever other HTML you want hereDIVs or SPANs or whatever, it doesn't matter as far as PHP is concerned. * It has to be defined by the time you try to use it. That means you define it in the same file (for the most part), or you define it in another file and require that file (at which point PHP will execute that file and "load" the function).
-
It's called "Math", not "math". Javascript is case-sensitive.
-
Send user back to same page without action set
requinix replied to Cyonis's topic in PHP Coding Help
Things happen in code because there is code to make the thing happen. Like a redirect. There is code to make the redirect happen. If you don't want the redirect to happen then you need to remove the code that does it. Yes I did restate your question, but that's because all I (thought I) needed to do to answer it: choose different words so that the question answered itself. Then, ironically, you need a redirect, except this time you redirect not to index.php but to the current page. And I think by "action" you mean the query string? What appears after the question mark in the URL? $_SERVER["REQUEST_URI"] contains everything in the URL after the hostname/domain name - including the query string. Such as "/pagename.php?action=logout". You can grab everything up to the query string with substr($_SERVER["REQUEST_URI"], strcspn($_SERVER["REQUEST_URI"], "?"))So redirect to that. However IMO a better course of action is to manually specify the URL. I know, manually sounds like a bad thing, but I can't imagine you have too many pages that need to do this redirect thing. No, they're not. Not in the technical sense at least. A script is a file, like pagename.php, while a function is an actual function foo() { ... } you defined in code somewhere. Regarding action vs query string, like I said I think you were talking about the query string. An "action", when used in a web/technical context, probably means a form action (as in where the form submits its data to). ...Either that or an "action" in the MVC sense, where "MVC" is a design pattern for developing websites (where a "design pattern" is basically just a good way of solving a common problem), but you can find out about that later.