sandy1028 Posted June 29, 2009 Share Posted June 29, 2009 Hi, The below code doesnot update the db. Please tell me where is the errror $array = array('”' => '"', '’' => '\\\'', '“' => '"', '‘' => '\\\'' ); foreach ($array as $key => $array) { echo "The key is $key: the array value is $entities_array\n"; $sq= mysql_query( "UPDATE table_name SET field_name=REPLACE(field_name, '".$key."', '".$entities_array."') WHERE field_name like '%$key%'") ; } Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/ Share on other sites More sharing options...
Adam Posted June 29, 2009 Share Posted June 29, 2009 Have you tried using mysql_error() to see if there's an error returned from the query? I'm assuming you've switched the table and field names to post on here? Do you get any PHP errors? Are they disabled? Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865559 Share on other sites More sharing options...
dzelenika Posted June 29, 2009 Share Posted June 29, 2009 Why don't you echo $sq and execute it in Database directly to see what happens? Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865561 Share on other sites More sharing options...
sandy1028 Posted June 29, 2009 Author Share Posted June 29, 2009 $sq= "UPDATE table_name SET field_name=REPLACE(field_name, '".$key."', '".$entities_array."') WHERE field_name like '%$key%'" ; $result = mysql_query($sq, $db_connect) or die(mysql_error()); No error... Actually I program takes time to execute. Is the iterating of array is wrong? Only the values of ” is updated with ". and iterating is not entered for the second element in array Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865562 Share on other sites More sharing options...
dzelenika Posted June 29, 2009 Share Posted June 29, 2009 should be: foreach ($array as $key => $value) instead of: foreach ($array as $key => $array) Don't you see that using $array variable twice? Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865564 Share on other sites More sharing options...
sandy1028 Posted June 29, 2009 Author Share Posted June 29, 2009 if I use the "$value", after the script execution prints the message " Query was empty"; Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865568 Share on other sites More sharing options...
Adam Posted June 29, 2009 Share Posted June 29, 2009 Where does $entities_array come from? Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865571 Share on other sites More sharing options...
sandy1028 Posted June 29, 2009 Author Share Posted June 29, 2009 Sorry it a $array. It was a typo. Even after removing $entities_array to $array, I get the message "Query is empty". But the row exists in the db. Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865574 Share on other sites More sharing options...
Adam Posted June 29, 2009 Share Posted June 29, 2009 Paste your full code. I can only assume at some point you've made a typo or accidentally changed a var. Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865585 Share on other sites More sharing options...
sandy1028 Posted June 29, 2009 Author Share Posted June 29, 2009 This is the full code $array = array('”' => '"', '’' => '\\\'', '“' => '"', '‘' => '\\\'' ); foreach ($array as $key => $value) { $sql= "UPDATE table_name SET field_name=REPLACE(field_name, '".$key."', '".$value."') WHERE field_name like '%".$key."%'" ; $result = mysql_query($sql, $db_connect) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/164085-update-doesnot-work/#findComment-865596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.