mysql-real-escape-string

PHP: using prepared statements and protecting against SQL injection vs escape

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 05:46:34
I do understand that the prepared statements is the ultimate way to seek protection against the SQL injection. However, they provide coverage in a limited fashion; for example, in cases where I let the user to decide how the order by operation to be ( i.e, is it ASC or DESC? etc ), I get no coverage there with the prepared statements. I understand that I can map the user input to a pre-defined white list for that. But, this is only possible when a whitelist can be created or guessed thoroughly beforehand. For example, in the cases I mention above ( the ASC, or DESC ), this can easily be mapped

Can't use mysql_real_escape_string

為{幸葍}努か 提交于 2019-12-04 20:03:50
So, I'm getting this warning when using mysql_real_escape_string Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'username'@'localhost' (using password: NO) in /home/path/php/functions.php on line 11 The rest of the site works fine, connects to the DB and all, but I get an error when using this function. It works completely fine on my localhost testing server. Any ideas? I use aforementioned function in my own homebrew string sanitation function: function sani($string){ $string = strip_tags($string); $string = htmlspecialchars($string); $string =

apostrophe like and equal clause not working

痞子三分冷 提交于 2019-12-04 19:41:56
I have one table named tags and it contain entry which is as below. ID Name Created Date 10 limit\'s 2013-06-27 05:18:35 Now i want to search for limit's using query but could not search record. For what i have tried. 'SELECT id FROM tags AS Tag WHERE name = "%'. urlencode($adTag) .'%" LIMIT 0,1' 'SELECT id FROM tags AS Tag WHERE name LIKE "%'. htmlspecialchars($adTag) .'%" LIMIT 0,1' 'SELECT * FROM tags AS Tag WHERE name LIKE "%'. $adTag .'%" OR REPLACE(name,'''','') LIKE "%'. $adTag .'%"' 'SELECT id FROM tags AS Tag WHERE name LIKE "%'. mysql_real_escape_string( stripslashes($adTag)) .'%"

mysql_real_escape_string() for $_SESSION variables necessary?

∥☆過路亽.° 提交于 2019-12-04 08:38:31
Should I use the mysql_real_escape_string() function in my MySQL queries for $_SESSION variables? Theoretically, the $_SESSION variables can't be modified by the end-user unlike $_GET or $_POST variables right? Thanks :) Regardless of whether the user can modify the data, you probably want to escape it anyway in case you ever need the data to contain characters that would break the SQL (quotes, etc). Better yet, use bound parameters and you won't have to worry about it. Do not escape/quote/encode text until you're at the point where you need it. Internal representations should be as "raw" as

Using mysql_real_escape_string with PDO (no connection to localhost server)

∥☆過路亽.° 提交于 2019-12-04 01:56:31
问题 So I'm fairly paranoid and use mysql_real_escape_string() with PDO. I actually don't use prepared statements in PDO, so I do have to sanitize the inputs. When hosting on my own server, I'd create an unprivileged user on the local machine so mysql_real_escape_string() wouldn't fail and empty my variable (heh, now that's sanitization!). I realize this is a pretty fail solution, since if the db's don't have matching charsets, then there's no point to the sanitizing at all, but it worked for the

Sanitizing PHP/SQL $_POST, $_GET, etc…?

半腔热情 提交于 2019-12-04 01:52:40
问题 Ok, this subject is a hotbed I understand that. I also understand that this situation is dependent on what you are using as code. I have three situations that need to be resolved. I have a form in where we need to allow people to make comments and statements that use commas, tildes, etc... but still remain safe from attacks. I have people entering in dates like this: 10/13/11 mm/dd/yy in English, can this be sanitized? How do I understand how to use htmlspecialchars() , htmlentities() and

Do I sanitize/escape correctly?

♀尐吖头ヾ 提交于 2019-12-03 00:39:23
问题 I've made a simple search-script in PHP that searches a mySQL database and outputs the result. How this works is like this: User searches for "jack's" through a search-form. My PHP-script GET s this search, and sanitizes it. Then the script, with the use of SELECT and LIKE , gets the results. The script then outputs the result to the user. Lastly, the script tells the user that "jack's returned x results." with the help of escaping. What I would like to ask is, am I doing it right? This is

Do I sanitize/escape correctly?

自作多情 提交于 2019-12-02 13:32:18
I've made a simple search-script in PHP that searches a mySQL database and outputs the result. How this works is like this: User searches for "jack's" through a search-form. My PHP-script GET s this search, and sanitizes it. Then the script, with the use of SELECT and LIKE , gets the results. The script then outputs the result to the user. Lastly, the script tells the user that "jack's returned x results." with the help of escaping. What I would like to ask is, am I doing it right? This is how I sanitize before SELECTING from the database: if(isset($_GET['q'])){ if(strlen(trim($_GET['q'])) >=

mysqli_real_escape_string() expects exactly 2 parameters, 1 given [duplicate]

我只是一个虾纸丫 提交于 2019-12-02 13:19:10
This question already has an answer here: PHP Error: Mysqli_real_escape_string() expects exactly 2 parameters, 1 given 5 answers I received this error when I run my code. Error: Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\wamp\www\SearchEngine\search.php on line 11 Code: <?php //php code goes here include 'connect.php'; // for database connection include 'script_suggestion.php'; include 'script_close_suggestion_box.php'; $query = $_GET['q']; // query $button = $_GET ['submit']; if (isset($_GET['page'])) { $page_number = (int)$_GET['page']; $page_number =

mysql_real_escape_string stopped working when I moved my code to another server

做~自己de王妃 提交于 2019-12-02 13:16:46
问题 The following code works perfectly fine in my local xampp installation (Windows 7), but when I ported it over to a Win2K8 R2 server, the mysql_real_escape_string piece does not work. When I comment it out, it works fine. I am pretty sure this has something to do with the php.ini file but cannot pinpoint what it is. Perhaps my code should have been written differently to begin with. function add_asset($asset_type_ID, $org_ID, $asset_desc, $asset_cost, $asset_value, $purchase_date) { global $db