|
WDF Regular
Join Date: June 2009
Location: Goldsboro, North Carolina, USA
Posts: 109
|
Absolute best way to stop hackers dead in their tracks, is to make sure that ANY and ALL input fields are protected with:
Code:
$post_this_val_instead = mysql_real_escape_string($_POST['some_field_name']);
Wham, all injections halted =)
http://us3.php.net/manual/en/functio...ape-string.php
Quote:
|
Originally Posted by teknicalissue
in my block of code
PHP Code:
class DeleteClass{
public function deleteSomething($item2,$uniqueField2,$table2){
$query = mysql_query("DELETE FROM '$table2' WHERE '$uniqueField2' = '$item2'");
if(!query){
echo mysql_error();
}
}
}
this returns an error... but if i remove the single quotes from the php variables in the query.. it works.. why??? i thought you were supposed to add single quotes to php variables in querys?
|
instead of using 's use `s instead...
PHP Code:
class DeleteClass{
public function deleteSomething($item2,$uniqueField2,$table2){
$query = mysql_query("DELETE FROM `" . $table2 . "` WHERE `" . $uniqueField2 . "` = `" . $item2 . "`");
if(!query){
echo mysql_error();
}
}
}
Also I broke the query up into a breaking string for you as well with the quotes and periods. When you use "'s in a query like that you're telling php to try and detect any variables in that string... Sometimes there aren't any and sometimes I just can't find them or thinks that it is not a variable where there is not a space before the variable... so '$variable would be skipped as a variable... Where as ' $variable would work. The safest way to do it is like so:
Code:
"SELECT * FROM `" . $tablename . "` WHERE....."
Last edited by Wired; June 10 '09 at 05:02 AM.
Reason: merged posts
|