-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
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).
-
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.
-
Yes, it will list mysql and possibly PDO and/or mysqli. Also note if it mentions "mysqlnd" anywhere.
-
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.
-
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.
-
SoapServer - how to add namespace to response
requinix replied to immortallch's topic in PHP Coding Help
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? -
display duplicate values in multidimensional array
requinix replied to cristyen's topic in PHP Coding Help
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. -
... 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.
-
Converting string to a number for calculation
requinix replied to mcmuney's topic in Javascript Help
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. -
display duplicate values in multidimensional array
requinix replied to cristyen's topic in PHP Coding Help
How about posting some more code? Like the stuff that queries the database, loads the numbers into the array, and outputs it all. -
count coding is working in localhost but in 000webhost i get error
requinix replied to Spraban9's topic in PHP Coding Help
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. -
Converting string to a number for calculation
requinix replied to mcmuney's topic in Javascript Help
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. -
count coding is working in localhost but in 000webhost i get error
requinix replied to Spraban9's topic in PHP Coding Help
That means the query failed. Use mysql_error to find out why. -
Then find a regular expression for emails, names, and numbers, probably looking like (email|name|number), then stick (?at the very beginning.
-
Find a regular expression for emails then stick (?at the very beginning.
-
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
-
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.
-
display duplicate values in multidimensional array
requinix replied to cristyen's topic in PHP Coding Help
-- Are you getting this array from a database? -
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]; } }
-
You have placeholders in the query but you never bind anything to them. Gotta put values in there.
-
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.
-
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?
-
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.