0

Here there is one table having field id, name,value. There is one form with field meta title, meta description, when I insert values are insert like

id    name              value
1     meta title        testtitle(this is value of textbox of meta title in form)
1     meta description  testdes

insert and delete function is working correctly but edit/update function is not working properly. here my update function :

function mysql_updatemetapost($db, $columns) {
    $sql = "";
    foreach ($columns as $obj) {
        $sql = "UPDATE user_metapost SET value = '{$obj['value']}' WHERE      
        user_postid='" . $obj['user_postid'] . "' AND name= '" . $obj['name'] . "'";
        $result = mysql_query($sql, $db) or die(mysql_error());
    }
    return $result;
}

Columns is an array contain data of form. here when updating records the name field value(meta title,meta description) should not be change, here in this code the problem is that when I update it will insert last value of columns array, it means meta description is updated, example :

after update table data are :

id    name                 value
1     meta description     updateddes(this is value of textbox of meta title in form)
1     meta description     updateddes
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
  • 1
    Please stop using mysql_* deprecated php api. It is no longer valid in PHP 7. Also turn to prepared statements since your code is vulnerable to SQL injections – Lelio Faieta Apr 19 '16 at 08:52
  • Try this [Insert array into MySQL database with PHP](http://stackoverflow.com/questions/10054633/insert-array-into-mysql-database-with-php) – rhavendc Apr 19 '16 at 09:14

0 Answers0