Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Problems Combining implode() with mysql_real_escape_string()

How do I correctly write the code for a MySQL query that both implodes and mysql_real_escape_string?

This is the code that I have, but it's failing:

$sql = "INSERT INTO BEER_LOCATIONS 
        (LOCATION_NAME, LOCATION_STREET, LOCATION_CITY, LOCATION_STATE,
        LOCATION_ZIPCODE, LOCATION_PHONE, BEER_STYLE ) 
    VALUES 
        ('" . mysql_real_escape_string(implode("', '", $row)) . "')";

Thanks

like image 793
Mark Avatar asked Dec 07 '25 10:12

Mark


1 Answers

implode("', '", array_map('mysql_real_escape_string', $row))

This applies mysql_real_escape_string to every element in $row and returns an array with the escaped values to implode.

like image 170
deceze Avatar answered Dec 10 '25 01:12

deceze