Please help mysql update problem!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phase1
Forum Newbie
Posts: 2
Joined: Tue Jan 27, 2009 12:25 pm

Please help mysql update problem!!

Post 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??
pl_towers
Forum Newbie
Posts: 12
Joined: Tue Jan 27, 2009 12:59 pm

Re: Please help mysql update problem!!

Post 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
phase1
Forum Newbie
Posts: 2
Joined: Tue Jan 27, 2009 12:25 pm

Re: Please help mysql update problem!!

Post 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?
Post Reply