Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Post not updating


12:56 am on Jul 12, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 24, 2009
posts: 113
votes: 0


Post not updating when submitted. Anyone can point out the problem here


if(isset($_POST['Submit'])) {
foreach (array_keys($_POST) as $key) {
$$key = $_POST[$key];
if (is_array(${$key})){
foreach(${$key} as $key2){
$$key2 = $_POST[$key2];
$$key = $_POST['$key'];

$st .= "$key = '$$key',";


if ($st) {
$st = preg_replace('/,$/','',$st);
$sql=mysql_query("UPDATE $db SET $st WHERE id='$id'") or die(mysql_error());


1:24 am on July 12, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

Presuming $id is a numeric value, and looking what you have there, I'd say it's empty or null. How? If it's empty,

..... WHERE id='$id'"

would give you

"UPDATE tablename SET field1='value1' WHERE id=''"

which would not error. But this

"UPDATE tablename SET field1='value1' WHERE id=$id"

would, because you do not have to quote numeric values and is one way to alert you to something like this.

I've I'm ten miles off, $id is all present and accounted for, what does this give you right after your loop?

echo "UPDATE $db SET $st WHERE id=$id";

Semantically (and more of a guess) I'd say "$db" is a dangerous variable to use for a table, $tblname might be better. It's not uncommon to assign $db to a database name, or a connection, maybe that could be the problem too?
3:51 am on July 12, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 24, 2009
votes: 0

hi rocknbil

Thanks for your info and the post script working now :)

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members