So after some advice here and in general web surfing, I've started using mysql_real_escape_string over addslashes, aaaand.... I've run into a problem I'm not sure how to handle. When I enter a multiline string into the database, mysql_real_escape_string replaces the \r\n in the string to a literal \r\n (that I can see in the mySQL data). I note that previously, with addslashes, this was not the case (I saw it as newlines rather then the characters). So of course, when I go to print out this data, and remove slashes, instead of newlines, I'm getting: blah blah blahrnbl
Articles similar to mysql_real_escape_string and new lines:
filter_input and mysql_real_escape_string don't mix?
Hello there. Consider this code:
PHP Code:
$string = filter_input (INPUT_POST, 'string', FILTER_SANITIZE_STRING);
$query = sprintf ('SELECT * FROM table WHERE username=\'%s\';',
mysql_real_escape_string ($string));
echo $query;
Slashes's Problem
I have having slashes problem, sometime it output \'s even though I have used mysql_real_escape_string
To insert data:
PHP Code:
$id = $_POST['id'];$name = mysql_real_escape_string($_POST['name']);mysql_query("INSERT INTO categories (id, name) VALUES ('$id','$name')");
Output:
PHP Code:
<?pho echo row['name']?>
Input data from UK: Testing's
Database: Testing's
Output data: Testing's
Input data from India: Testing's
Database: Testing\'s
Output data: Testing\'s
What is the problem?Error Message Help Please
Hi,
I am getting the following error message:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established on line 18
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) on line 18
But I have set up my ODBC connection and my password and details should be correct.
My code is:
Code:
<?php
function check_input($value)
{
if (get_magic_quotes_gpc()){
$value=stripslashes($value);
}
if (!is_numeric($value)){applying mysql_real_escape_string to a whole array
Ok, here's an easy one, I want to apply mysql_real_escape_string to all the elements in an array so that I can use them already escaped without having to do so explicitly to each one.
So, for example, the elements are like so:
PHP Code:
mysql_real_escape_string($entryArray["title"])
mysql_real_escape_string($entryArray["duration"])
... etc
Now, here is where it gets tricky, the array is a multidimensional array like so:
array(30) {
["dateAdded"]=>
float(1092337200)
["media"]=>
string(3) "DVD"
["lentHistory"]=>
array(1) {
[0]=>
array(2) {import question
I have a php script that generates a Mysql string that imports information from a csv file into a Mysql database. I can import new records from the database but not update existing records. I am thinking this is a Mysql string problem and not a php issue.
This one works fine... It imports new records into the database.
LOAD DATA LOCAL INFILE 'C:/wamp/www/test/files/upd101010.csv' INTO TABLE email FIELDS TERMINATED BY ',' LINES TERMINATED BY ' \r\n ' IGNORE 1 LINES (fname, lname, city, state, zip, eaddress, reason, message);
This one will not update the existing records...
Protecting your data?
Hello,
Im becoming a wee bit paranoid about attacks on mysql database, making sure my data is safe and nobody can get at it through my online forms I have.
I currently:
1) Run all queries through mysql_real_escape_string()
2) Have register_globals directive is disabled
3) Clean all my $_POST variables through html_entities like so, that way no Javascript etc can be insterted:
PHP Code:
$name = trim(htmlentities($_POST['name'],ENT_QUOTES));
4) Perform regex expressions on my form to make sure things like an email address is ACUTUALLY an email address.
5) Have a CATCHPA system in place
Now I have two questions:
Sub Domain Sitemap question
Hi guys, I have a question about subdomain sitemaps that hopefully i can explain correctly.
I am making a site that will be a php backend that will allow users to create their own subdomains for a personal web page. when the subdomain BLAH is created it will be in the directory www.example.com/BLAH. so BLAH.example.com = www.example.com/BLAH.
my plan is that on creation of the BLAH.example.com a sitemap.xml containing just the index.php will be created in the root of BLAH.example.com. search engines then will be automatically be pinged that sitemap.
NOW, since the subdomain is actually a directory in the main domain(www.example.com), i can also add www.example.com/BLAH to main domains sitemap.xml and ping that too.

