Hello, I would like to ask some help regarding in this code foreach ($_POST as $field => $value){ if($value != 'Update'){ //INSERT the value of each field into mysql using //mysql_query(INSERT INTO mytable ( field1, field2, field3)VALUES( $value1, $value2, $value3); } } PHP: I want to INSERT the value of every fields in mysql database if i click the submit button, any idea? please help. Thanks
why not try to build first your query string $fields = ''; $values = ''; $count = 0; foreach ($_POST as $field => $value){ $comma_delimiter = $count < count($_POST) ? ', ' : ''; $fields .= $field . $comma_delimiter; $values.= $value . $comma_delimiter; } $sql = 'insert into table ('. $fields .')' values ('. $values .')'; hows that?
include('database.php'); $database = new database($yourdatabaseconnection); $database->insert('mytable',$_POST); // To delete a user (primary key detected automatically) $database->delete('mytable',$primarykeyValue); PHP: Download Just make sure that the primary key is part of that $_POST, otherwise it will add it instead of updating it. Currently that database class hasn't been released except for the AzizMVC application, I will be releasing it soon standalone. It has other features that you might like. This requires PHP 5 & up.