homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Post not updating

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

hi rocknbil

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved