Re: using mysql_escape_string with implode() - SOLVED!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ave,

Alright, here's I solved it. Used the array_walk function. This is my code:

function test_alter(&$item1) {
$item1 = mysql_escape_string($item1);
}
array_walk($var, 'test_alter');
$var = implode("','", $var);
        
$sql = "INSERT INTO
nimo_account(Date,Time,Phone,Account,AccountType,RateClass,VoltLevel,IsoZone
,TaxDist,LoadProfile,ServiceName,ServiceAddress,ServiceCity,ServiceState,Ser
viceZip,Demand,Kwh,Cost) VALUES ('$dt','$tm','$thephone','".$var."')";
$result = mysql_query($sql) or die("Critical Error: ".mysql_error());

And it Works! 
All special characters are escaped within the Array's Values itself, and
then I just implode them with ',' and add them to the mySQL Database!!


On 5/25/07 11:32 AM, "Rahul Sitaram Johari" <sleepwalker@xxxxxxxxxxxxxxxx>
wrote:

> 
> Ave,
> 
> I¹m inserting values out of an array into mySQL. There¹s other values besides
> the array values that are being inserted as well. This is my simple INSERT
> code:
> 
> $sql = "INSERT INTO db
> (Date,Time,Phone,Account,AccountType,RateClass,VoltLevel,IsoZone,TaxDist,LoadP
> rofile,ServiceName,ServiceAddress,ServiceCity,ServiceState,ServiceZip,Demand,K
> wh,Cost) VALUES ('$dt','$tm','$thephone','".implode("','",
> array_values($var))."')";
> 
> $var can contain values that have special characters that I need to escape.
> I¹d like to use mysql_escape_string() but I¹m not sure how to integrate
> mysql_escape_string here with the INSERT statement. I tried it, but it¹s not
> working. Any clues?
> 
> Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux