setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH..." />

Can you use parametrized PDO to add columns AND values?

Use: $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set " . $update . " where id = :id" ); //$STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute() instead of: $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set :update where id = :id" ); $STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute() Or you can use this: if( $_SERVER'REQUEST_METHOD' == 'POST' ) { $fields = array('db_field1'=>'cb1', 'dbfield2'=>'cb2', 'dbfield3'=>'cb3', 'dbfield4'=>'cb4'); $update = array(); $values = array(); foreach($fields as $dbfield => $field) { $update = $dbfield ." =?

"; $values = isset($_POST$field)? 1 : 0; } $values = $id; $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH->prepare( "update table1 set " . Join( ',', $update ) .

" where id =? " ); $STH->execute($values); } instead of: if( $_SERVER'REQUEST_METHOD' == 'POST' ) { $fields = array('db_field1'=>'cb1', 'dbfield2'=>'cb2', 'dbfield3'=>'cb3', 'dbfield4'=>'cb4'); $update = ''; foreach($fields as $dbfield => $field) { if ($update) $update. = ','; $update.

= ' '. $dbfield.'='; if (isset($_POST$field)) { $update. = 1; } else { $update.

= 0; } } $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set :update where id = :id" ); $STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute(); }.

Use: $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set " . $update . " where id = :id" ); //$STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute(); instead of: $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set :update where id = :id" ); $STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute(); Or you can use this: if( $_SERVER'REQUEST_METHOD' == 'POST' ) { $fields = array('db_field1'=>'cb1', 'dbfield2'=>'cb2', 'dbfield3'=>'cb3', 'dbfield4'=>'cb4'); $update = array(); $values = array(); foreach($fields as $dbfield => $field) { $update = $dbfield ." =?

"; $values = isset($_POST$field)? 1 : 0; } $values = $id; $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH->prepare( "update table1 set " . Join( ',', $update ) .

" where id =? " ); $STH->execute($values); } instead of: if( $_SERVER'REQUEST_METHOD' == 'POST' ) { $fields = array('db_field1'=>'cb1', 'dbfield2'=>'cb2', 'dbfield3'=>'cb3', 'dbfield4'=>'cb4'); $update = ''; foreach($fields as $dbfield => $field) { if ($update) $update. = ','; $update.

= ' '. $dbfield.'='; if (isset($_POST$field)) { $update. = 1; } else { $update.

= 0; } } $DBH = new PDO( "mysql:host=localhost;dbname=database", "user", "pass" ); $DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $STH = $DBH -> prepare( "update table1 set :update where id = :id" ); $STH -> bindParam( ':update', $update, PDO::PARAM_STR, 255 ); $STH -> bindParam( ':id', $id, PDO::PARAM_INT, 4 ); $STH -> execute(); }.

– oshirowanen Jul 19 at 8:22 No, it doesn't. I will add one more variation of what you could do. – Eugene Manuilov Jul 19 at 13:17 Check second version – Eugene Manuilov Jul 19 at 13:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions