Simple PHP function safe against SQL injection?

fightstarr20

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?

Themis Beris

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is merging variables safe against SQL injection?

From Dev

Effective protection function against SQL injection

From Dev

Is the switch-function SQL-injection safe?

From Dev

Is this SQL query, injection safe

From Dev

PHP - Does PDO quote safe from SQL Injection?

From Dev

PHP - Does PDO quote safe from SQL Injection?

From Dev

PHP sql Injection and custom numbers of parameters in function

From Dev

Is this code safe from SQL Injection?

From Dev

Best way to protect against SQL injection in SqlDataAdapter

From Dev

Protecting against sql injection using activerecord

From Dev

PHP conversion against injection for numerical parameters

From Java

Is this raw SQL statement safe from SQL Injection?

From Dev

SQL Injection function of ' -- +'

From Dev

Is this function vulnerable to SQL injection?

From Dev

SQL Injection function of ' -- +'

From Dev

Is the @Query annotation in spring SQL Injection safe?

From Dev

is find_by_id sql injection safe in rails?

From Dev

Safe code for SQL Injection using mysql_*

From Dev

Is Doctrine persist() safe from SQL injection?

From Dev

Am I safe?? [trying to prevent sql injection]

From Dev

SQL injection attack with php

From Dev

PHP 5.4 SQL Injection

From Dev

SQL injection attack with php

From Dev

PHP SQL injection prevention

From Dev

SQL Injection on php

From Dev

Running QuickCheck against Simple Test w/ Function

From Java

Do I have to guard against SQL injection if I used a dropdown?

From Dev

Does passing XML as a parameter protect me against SQL injection?

From Dev

The best way to secure yourself against sql injection in nodejs