Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. What (example) numbers are you getting and what were you expecting? Also, you should set up your environment for development by making sure you know about errors and warnings as they come up. Open up your php.ini and set error_reporting = -1 display_errors = onand try your code with a percentage of
  2. Turn off the magic_quotes php.ini setting. Then do a pass over any other code you might have to make sure you are being safe with SQL queries and the like (which addslashes() doesn't count towards).
  3. Yes, then you do a mysqli::prepare(), mysqli_stmt::bind_param(), and mysqli_stmt::execute(). (Then fetch the results.) Take a look at mysqli in the manual. Besides the documentation there's plenty of examples and user comments.
  4. Yes, it will list mysql and possibly PDO and/or mysqli. Also note if it mentions "mysqlnd" anywhere.
  5. First is to make sure you're using the PDO or mysqli extensions. Not the mysql extension (whose functions are all named mysql_*) because it's old and not as useful. Once you've switched, PDO and mysqli both support prepared statements where you can write a query with variables select items from table_name where state = ? (mysqli) select items from table_name where state = :state (pdo)and then bind the state name to that variable. Then you don't have to worry about SQL injection at all: no need to quote stuff, no need to escape stuff.
  6. Load up the HTML in DOMDocument, then do a getElementsByTagName() to find that link. If you know the URL will always follow some structure then you can "find that link" by checking all the hrefs until you get the right one. Otherwise you can look for a target=_blank attribute and inner HTML of "Continue". Both methods can break if they change the site enough. So... what's this for? It's odd that they're changing the link you need so often.
  7. The only difference between the two is that the "proper response" includes an xmlns for a namespace that isn't used anywhere. It doesn't matter. So are you trying to do this for cosmetic purposes or is there a functional problem somewhere?
  8. It doesn't make sense to have a search page be the homepage. Even if the homepage is a big wall of text, if the user wants to search and you make the search link prominent enough then they can just go directly to search. Meanwhile it doesn't confuse people who do want to read the introduction.
  9. array_count_values() should work at that point, except it doesn't work on non-string, non-integer array items (because they end up as array keys). So you have two options: 1. Multiply everything by some constant so that everything is an integer (like 2 or 10), then count. $TableauNotesCounts = array_count_values(array_map(function($a) { return $a * 2; }, $TableauNotes)); 2. Since 6 is apparently the magic number, do this work in that code you had earlier that calculated the totals. At its simplest, keep an array of counts $TableauNotesCounts = array(); and add to it when you calculate something for $j=6. It's trickier because you can't just use 6.0 or 4.5 as array keys... if ($j == 6) { if (isset($TableauNotesCounts[$Note * 2])) { $TableauNotesCounts[$Note * 2]++; } else { $TableauNotesCounts[$Note * 2] = 1; } } In both cases, when you loop over the array of counts you'll need to divide the key by the constant (eg, 2) to get the original score.
  10. ... What you posted is way too specific to be actual input from a user. Also doesn't make sense to enter search terms like that when you can run arbitrary SQL. So that's the SQL generated by your site, which you are supposed to be familiar with, including information provided by the user. The spam information. I can't know more about your site than you do but I can tell you with reasonable certainty that it was neither an attack nor was putting your site at risk. With that said, go learn how your own site works.
  11. When I asked what you needed the width for I wasn't looking for an answer like "to do stuff with it". What is "do X"? What is "do Y"? Are you absolutely positive that you can't do both, conditionally, client-side? Because if not then you have to display a page first, use Javascript to get the screen dimensions, then reload the page passing along the numbers.
  12. How about posting some more code? Like the stuff that queries the database, loads the numbers into the array, and outputs it all.
  13. As long as the query worked, $profile will be set to something. empty($profile) won't tell you if there were any results, and you won't get an error trying to fetch from a (successful) resultset even if it's empty.
  14. You can't mix and match PHP with Javascript like that. What do you need the width for? It might have to wait until the page has been displayed - you can't get the screen width any earlier than that, but you might be able to do something else that doesn't require having the numbers in front of you.
  15. That means the query failed. Use mysql_error to find out why.
  16. Then find a regular expression for emails, names, and numbers, probably looking like (email|name|number), then stick (?at the very beginning.
  17. Find a regular expression for emails then stick (?at the very beginning.
  18. Ah, okay, it makes sense now. If you can safely array_filter $_POST, which will automatically prune out empty array values, then it's as simple as $required = array("A" => "Field A", "B" => "Field B", "C" => "Field C"); $diff = array_diff_key($required, array_filter($_POST)); Otherwise $required = array("A" => "Field A", "B" => "Field B", "C" => "Field C"); $missing = array(); foreach ($required as $name => $label) { if (empty($_POST[$name])) { $missing[] = $label; } } (assuming I understand you correctly this time) [edit] #$^(*@#, code tags are killing my indentation again
  19. So... you're not asking about how to provide a "default" value for something in case one wasn't provided in the form? Because that's really what it sounded like.
  20. -- Are you getting this array from a database?
  21. Have you considered using both the key and the value in that foreach? You were so close. // $_POST = array("A" => "", "B" => "Original B"); $defaults = array("A" => "ValueA", "B" => "ValueB", "C" => "ValueC"); $items = array(); foreach ($defaults as $key => $value) { if (empty($_POST[$key])) { $items[$key] = $value; } else { $items[$key] = $_POST[$key]; } }Or you can just use one array.$items = array("A" => "ValueA", "B" => "ValueB", "C" => "ValueC"); foreach (array_keys($items) as $key) { if (!empty($_POST[$key])) { $items[$key] = $_POST[$key]; } }
  22. You have placeholders in the query but you never bind anything to them. Gotta put values in there.
  23. If you want help you'll have to explain stuff. Giving us a small screenshot like that says absolutely nothing about how it's supposed to work.
  24. You can't mix PHP and Javascript like that. Are you trying to get the value of a cookie? Have you looked at PHP's $_COOKIE superglobal yet?
  25. For the character encoding mb_detect_encoding() or at worst a regex can work. Use mb_strlen() for the string length in a multibyte encoding, otherwise the binary strlen() is fine. Right. I said htmlentities() first, nl2br() second. You're demonstrating the reverse order.
×
×
  • 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.