kabar916 Posted October 10, 2011 Share Posted October 10, 2011 Whats going on you guys. i cant figure out how to use the UPDATE function in php to update a field in sql. I basically want to remove all the quote symbol ( " ) in a certain field. This is what how i wrote it. please let me know where im making the error. <?php require_once("includes/connection.php"); $result = mysql_query("UPDATE export SET department = REPLACE(department, '\"\',' ')", $connection) ?> Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/ Share on other sites More sharing options...
MarPlo Posted October 10, 2011 Share Posted October 10, 2011 Hi, I think it's a problem with a slash, try this: $result = mysql_query("UPDATE export SET department = REPLACE(department, '". '"'. "',' ')", $connection); Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/#findComment-1277779 Share on other sites More sharing options...
Muddy_Funster Posted October 10, 2011 Share Posted October 10, 2011 You only have 1 slash too many, but you need an extra set of parenthesis around the whole REPLACE statement: $result = mysql_query("UPDATE export SET department = (REPLACE(department, '\"',' '))", $connection); Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/#findComment-1277807 Share on other sites More sharing options...
kabar916 Posted October 11, 2011 Author Share Posted October 11, 2011 Thanks for the help. that solved that problem. do you know how to remove the qoutes sign in the hold table or do i have to do one field at a time Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/#findComment-1278026 Share on other sites More sharing options...
Muddy_Funster Posted October 11, 2011 Share Posted October 11, 2011 you could put it in a loop: $qry = "SHOW COLUMS FROM export"; $loop_result = mysql_query($sql) or die (mysql_error()); $c= 0; while ($loop_row = mysql_fetch_array($loop_result)){ $field = $loop_row['Field']; $sql = "UPDATE export SET $field = (REPLACE(department, '\"',' '))"; $update = mysql_query($sql) or die (mysql_error()); $c = $c++; } if($c >= 1){ echo "$c Fileds have been successfuly reformated"; } else{ echo "Operation did not update any rows"; } Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/#findComment-1278280 Share on other sites More sharing options...
kabar916 Posted October 13, 2011 Author Share Posted October 13, 2011 thanks a lot bro. you saved a lot of work. Quote Link to comment https://forums.phpfreaks.com/topic/248783-php-with-sql-help/#findComment-1278865 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.