English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

file 1/ querydb.html------------------------------------
...


<...name='query' ...>$query<...


file 2/ querydb.php----------------------------
...
$query = "$_POST[query]";
$query = stripcslashes($query);
mysql_query($query, $conn)or die(mysql_error());


If I POST any $query with (') from file 1
ex. $query="update subscribers set name='theo' where..."

it will be received by file 2 like
$query = $_POST[query]="update subscribers set name=\'theo\' where..."

and then stripcslashes($query)="update subscribers set name='theo' where..."

If the query is not correct
(ex: ...("updata subscribers set name='theo' where...")
It will not be executed and there will be no
return of mysql_error().

But----------------------------------------------------------
If I pull out of the code the line
$query = stripcslashes($query);
then the query of course is not correct and will not be executes
(ex: ..."update subscribers set name=\'theo\' where...")
but
this code RETURNS the mysql_error().

Thank you for reading

2006-07-02 08:05:07 · 1 answers · asked by anandsamyo 1 in Computers & Internet Programming & Design

1 answers

What is MySQL error you are recieving? A better way to prevent SQL injection for this sort of thing is to use PDO as a database abstraction layer (www.php.net/PDO/). Using PDO you would just do:
$query="UPDATE subscribers SET name = :name WHERE...";
$stmt=$connecton->prepare($query);
$stmt->execute(array(":name"=>$name));

2006-07-02 08:14:58 · answer #1 · answered by John J 6 · 0 0

fedest.com, questions and answers