Welcome to WebmasterWorld Guest from 54.166.220.138

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Post not updating

post

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

5+ Year Member



hi

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


<?php

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 Jul 12, 2010 (gmt 0)

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



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";
exit;

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 Jul 12, 2010 (gmt 0)

5+ Year Member



hi rocknbil

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

Featured Threads

Hot Threads This Week

Hot Threads This Month