I have a simple routine that deletes a row from an SQL database..
<?php
global $wpdb, user_ID;
$tmp_mid = $_GET['mid'];
if (!empty($tmp_mid))
{
$id_check = $wpdb->get_var($wpdb->prepare("SELECT message_to_user_ID FROM " . $wpdb->base_prefix . "messages WHERE message_ID = %d", $tmp_mid));
if ( $id_check == $user_ID )
{
$wpdb->query( $wpdb->prepare("DELETE FROM " . $wpdb->base_prefix . "messages WHERE message_ID = %d", $tmp_mid ));
}
}
?>
I want to ensure that the row can only be deleted if the $user_ID matches the $tmp_mid from the row. All seems to work correctly but is this routine vulnerable to SQL injection?
Do I need to do anything to it to secure it?
Your code is not vulnerable to SQL-Injection
.
Edit: As DCoder pointed out, you are safe from sql-injection
because this wp method runs finally the mysqli_real_escape_string()
function where your input is sanitized properly ! Still you do not make use of prepared statements, but it's fine .
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments