I'm running into the following problem:
I've a client area where开发者_如何学编程 my client can edit 3 image fields. The problem is:
I just want to update the photo name in the database for the fields that are not empty. So, for example, if my client decide to change photo #2, I need a mysql update that will not override photo #1 and #3.
I could write a lot of "if" statements but I think there's a better way to do it.
any help?
Maybe you could use an array and a foreach
statement. It could be something like:
$field = array();
$field['1'] = $_POST['field1'];
$field['2'] = $_POST['field2'];
$field['3'] = $_POST['field2'];
foreach($field as $value){
if($value != NULL){
// Update the MYSQL database for the field using $value to figure
// out which field the script is on
}
}
精彩评论