Page 1 of 1

Please help mysql update problem!!

Posted: Tue Jan 27, 2009 12:33 pm
by phase1
I'm trying to update a mysql database from within a function: the code is as follows:

<?php
function stuff($topic, $zoo){


foreach($paragraphs as $paragraph){
$paragraph = strip_tags($paragraph);
$paragraph = quotemeta($paragraph);
$paragraph = addslashes($paragraph);
if ($paragraph){
$final = $final . $paragraph . "\n\n";
$new_string = substr($final, 0, 2000);


}
}
include ('config.php');
$splitup = explode(',_', $topic);
$City2 = strtoupper($splitup[0]);
$State2 = $splitup[1];

$sql2 = 'UPDATE `zip_codes` SET `City_Desc`="$new_string" WHERE `City`="$City2" AND `State`="$State2" AND `Zip`="$zoo"';
mysql_query($sql2) or die(mysql_error().mysql_errno());
}

?>

There is no problem with the variables getting to the sql statement (i've echoed the variables and they all show up correctly), but for some reason, it just won't insert and there is no error that seems to show up.

I've used the exact same code for the update statement on a different page, and it seems to update the db just fine.

Does anyone know what i'm doing wrong??

Re: Please help mysql update problem!!

Posted: Tue Jan 27, 2009 1:26 pm
by pl_towers
I cant see what your code is supposed to be doing but if my sql statements ever do anything funny and i dont get an error i echo out the sql statement and run it in the phpmyadmin usually shows what the problem is

Re: Please help mysql update problem!!

Posted: Tue Jan 27, 2009 2:30 pm
by phase1
the function seems to work fine when i run it in phpmyadmin, but when i try to add it into the code, everything comes up blank with no error msg - is there a problem with running and update query inside a function?