Jump to content

requinix

Administrators
  • Posts

    15,066
  • Joined

  • Last visited

  • Days Won

    414

Everything posted by requinix

  1. And a third thing, if(!$stmt){will never be true. $stmt->execute(array( 'recordid' => $record_id, 'name' => $name, 'content' => $content ));The array to execute() uses names like "recordid" but it needs to match exactly the placeholder used in the prepared statement, $stmt = $db->prepare("INSERT INTO records(record_id, name, content) VALUES(:recordid, :name, :content");so that means it should be like ":recordid" instead.
  2. Copy/paste fail: you're trying to validate the subject like an email address.
  3. Taking a guess, The URL has to be absolute. That means a leading slash and the full path to where poll.php is. $.post('/path/to/poll.php', $(this).serialize(), function(data, status){
  4. ...no. First, open source is a concept - a license, really - not an implementation. You don't have to host your code on GitHub for it to be open source, and putting it on GitHub doesn't make it open source. Second, GitHub and others are code repositories. You don't keep your code there and then try to run it from there. It's a place you can store your files on the internet. When you want to run them, you download them (in the case of GitHub, using git) and run them. Locally. You could just as well put the files in a .zip on an FTP server and download the code for all it matters.
  5. Where is the array? It has to be somewhere in the HTML or in the Javascript (or retrieved from the server through AJAX).
  6. PHP will add files in the order they're presented, so it's up to the drag and drop code to deal with that. You can still sort in PHP, of course. There are four arrays in $_FILES that you have to sort at once so rather than sort() use array_multisort: you give it the four arrays (name, tmp_name, error, type) and it'll sort one and rearrange the rest accordingly. Check the examples there and give it a shot.
  7. FYI there was a non-breaking space in your link that was breaking (ha) it. I removed it. Which suggests to me another problem. If you copy/paste the code you posted (either from here or Digital Point) to replace what you have now, does it work?
  8. DECLAREs have to come before everything else.
  9. PHP has no idea you're trying to call a function named "getCardValues". As far as it knows, there's a whole bunch of text and then suddenly $pyramid and then a lot more text after. It's not going to try to guess what you want. You can use a variable and that's it. So put your getCardValues() stuff into a variable, do the same for the others, and insert those variables where you want the values to appear.
  10. The third, if pwm contains "#lblpasswordmessage". Or if it doesn't include the hash sign then $("#" + pwm)
  11. And if there's a space in front of the comment? Or a lone semicolon? [edit] And while I'm here, how are these files being executed? And what do you get if you do <?php //my comment //my comment //my comment //my comment //my comment echo "<pre>\n"; print_r(file(__FILE__)); echo "\n</pre>\n"; ?>
  12. Rely on it in the sense that what you see is going to be what the server sees. Sure, I can stick a %PNG into whatever I want and make my .zip look like an image, however the server is going to use the same logic to come to the same conclusion. Even if I ignore the MIME type, the rest of the system may not, so I'd rather derive the same results as it will now than leave the question unanswered. Strictly speaking yes, data is data and harm only comes from using it incorrectly. But there are more ways to harm a system than waiting for a user to try to download the file to their computer or otherwise execute it. If the file is malicious I don't want it on my server. Period. I don't care if the web server won't try to interpret it, I don't care if the file sits unused for eternity, it should not be there at all. Ideally, yes, but I don't know of an operating system where you can specify the behavior of an individual file without having to rely on things like MIME type detection or file extension mappings. I'm sure we're on the same page regarding validation
  13. Just because it's not enough doesn't mean it's useless. Assuming we're talking about determining the MIME type server-side and not getting it from $_FILES, of course. - Best way to determine the proper file extension when it's not known ahead of time - Good indication as to how an operating system (and to a lesser degree, your server) will interpret the file, if combined with using the correct file extension - Provides validation for the good users - Quick way to deny lazy attackers who aren't forging their own upload requests
  14. It's an important skill to be able to read dumps like this. $stock = (array(1)$stock is an array with one item. { ["stock"]=> array(2)The key is "stock" and the value is another array, this time with two items. { [0]=> array(2)The first key is 0 suggesting the parent array is something you should foreach over. The value is another array. { ["operator"]=> string(3) "ECL" ["sims"]=> array(51)In the array are two items, "operator" (a string) and "sims" (yet another array). All together, foreach ($stock["stock"] as $stock) { foreach ($stock["sims"] as $sim) {
  15. I'm confident that the official manual did not tell you to do ranges using a switch. I'm looking now and I don't see anything telling you to do that. In fact I had to go into the user comments until I found something to do with ranges: this guy from a few years ago. (There were other comments like that but were all rated $randomizer = rand(1,50); switch($randomizer) { case ($randomizer <= 20): $font_size = "11"; break;That code is wrong and I just downvoted the comment for it. It will always work, yes, but if I made a tiny change to it $randomizer = rand(0,50); switch($randomizer) { case ($randomizer <= 20): $font_size = "11"; break;then there's a 1/50 chance that it will fail, PHP will raise an undefined variable warning, and the CSS in the outputted HTML echo '<span style="font-size: ' .$font_size. ';">' .$link[$i]. '</span> ';will be invalid. actually it's a 1/51 chance The only change I made was going from rand(1,50) to rand(0,50). So what? I added one more number, that's all. And that's the problem: it's not obvious why the code will fail, it'll be hard to reproduce, and you the developer will tear your hair out trying to figure out why there's this weird bug on your site that people are complaining about. Just because you yourself cannot see the problem doesn't mean there isn't one. Using your code from a few posts ago, switch($magnitude) { case $magnitude >=0 && $magnitude <=0.9: $magScale = 'rgb(195, 218, 236)'; break; case $magnitude >=1 && $magnitude <=1.9: $magScale = 'rgb(210, 238, 197)'; break; case $magnitude >=2 && $magnitude <=2.9: $magScale = 'rgb(244, 240, 202)'; break; case $magnitude >=3 && $magnitude <=3.9: $magScale = 'rgb(244, 223, 202)'; break; case $magnitude >=4 && $magnitude <=4.9: $magScale = 'rgb(240, 199, 205)'; break; case $magnitude >=5 && $magnitude <=20: $magScale = 'rgb(212, 195, 236)'; break; }set $magnitude = 0 and see what happens. Should be pale blue, right? Nope. Now forget for a moment that $magnitude "should not" ever be 0 and think about the fact that your code did something it wasn't supposed to. And it's another way that would force you to get the logic right. If you tried that switch above as an if/else then I'm sure you'll see the behavior is different. If you're saying what I think you're saying, No. That is flat-out wrong. If two cases are both true at once then one of them will win. However, because of the bug in (the old version? of) your switch, you may have gotten the result you did because none of the cases matched the switch condition. Now I phrased that last sentence very carefully so if you want to show the code you had as a way to prove I'm wrong, it won't work. Oh. Not "the old version" then. Keep this thread in mind when you get weird behavior from a switch. And I do mean "when", not "if". I don't know what code you tried for those two attempts but the switch(TRUE) is in the correct form. Note "correct form". The reason it doesn't work is because of the conditions. Look at them: case $LRH_calcDepart >=0 && $LRH_calcDepart <=-2:Please give me an example value of $LRH_calcDepart that will satisfy that condition.You'll get light purple for every value >= -10 because that last case there is the only one that could ever possibly match. Texan knows something that has never been wrong in his/her experience. We're saying that it is, in fact, wrong. It's good to be a bit stubborn.Of course I'm still hoping for that "ah ha" moment where everything we're saying clicks.
  16. MailChimp has an api for doing exactly this. Have your code send a subscribe request to MailChimp instead of using the form method.
  17. My feedback would be the same as mattficken's. Bug #68578 MS-Access's Linked tables are Not supported on PHP
  18. It's working for the wrong reasons so it's teaching you the wrong way to use a switch. This time it works, sure, but next time it won't and you won't understand why because "it worked that other time".
  19. That won't work either. if ($magnitude == ($magnitude >= 0 && $magnitude Seeing the pattern yet? what you put in the switch == each case Really. Forget the switch and go with a normal if. if ($magnitude >= 0 && $magnitude
  20. A switch (just called "switch") doesn't really do ranges. It's a fancy way of doing a lot of if/else ifs. switch ($value) { case $condition1: // if ($value == $condition1) case $condition2: // else if ($value == $condition2) ...What you've written is if ($magnitude == (myInterval >= 0 && myInterval <= 0.9)) { $magScale = 'rgb(195, 218, 236)'; } else if ($magnitude == (myInterval >= 1 && myInterval <= 1.9)) { $magScale = 'rgb(210, 238, 197)'; // ...which doesn't make sense, least of all because of whatever the "myInterval" thing is. There is a way to do this with a switch but it looks weird so you might as well just use a regular if block. if (myInterval >= 0 && myInterval < 1) { $magScale = 'rgb(195, 218, 236)'; } else if (myInterval >= 1 && myInterval < 2) { $magScale = 'rgb(210, 238, 197)'; // ...Note that I switched the second condition to a strict less-than: I don't know your application or the values of myInterval but it's safer to make sure there's no possible value being missed out on, and with the current version if myInterval=0.95 then nothing will happen. Even if you're sure that "0.95" won't happen.
×
×
  • 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.