问题foreach下拉选择中的UPDATE特定行

我尝试更新成员表,在foreach循环中,其中memberID =:memberID,但它没有按我的预期工作,此代码应在成员表---->“横幅”行中进行更新,值来自于下拉选择项来自另一个数据表。在成员表UPDATE之后,下拉操作仅更新最后输入的数据。

你能帮忙吗? 无法弄清楚出什么问题了,我简短地说。 任何帮助都是极好的!!!

代码在这里:

<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_USER_NOTICE);
ob_start();
session_start();

//database credentials
define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','root');
define('DBNAME','dbname');

$db = new PDO('mysql:host='.DBHOST.';dbname='.DBNAME.';charset=utf8mb4', DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>

<section>
<table>
<thead>
<tr>
<th>ID</th>
<th>Banner</th>

</tr>
</thead>
<tbody>
<?php
try {


$op_bn='<option disabled selected>Select Banner</option>';
$stmt = $db->prepare('SELECT * FROM banners');
$stmt->execute();
$result = $stmt->fetchAll();
$img_limk = '<img style="width:50px; height:50px;" src="../'.$row['bannerSlug'].'">';
foreach ($result as $row) {
$op_bn.= "<option value='" . $row['bannerSlug'] . "'>" . $row['bannerTitle'] . "</option>";
}


$stmt = $db->query('SELECT memberID, banner FROM members ORDER BY memberID DESC');
$stmt->execute();
$result = $stmt->fetchAll();


foreach($result as $row) {

echo '<tr>';
echo '<td>'.$row['memberID'].'</td>';

###########################################################################PROBLEM HERE
###########################################################################

if(isset($_POST['bannerTitle'])){


$memberID = $row['memberID'];
$banner = $_POST['bannerTitle'];

$stmt = $db->prepare('UPDATE members SET banner=:banner WHERE memberID=:memberID');
$stmt->execute(array(
':banner' => $_POST['bannerTitle'],
':memberID' => $row['memberID']
));


$_SESSION['success'] = "Banner successfully added to member profile!";
header('Location: view_members.php');
exit;
}

echo '<td><form method="post" action=""><select name="bannerTitle" onchange="this.form.submit()">'.$op_bn.'</select></form</td>';


###########################################################################PROBLEM HERE
###########################################################################


echo '<td><img style="width:50px; height:50px; display:block; overflow:hidden;" src="../'. $row['banner'] .'"></td>';
echo '</tr>';


}


} catch(PDOException $e) {
echo $e->getMessage();
}
?>
</tbody>
</table>
</section> 

会员表:

CREATE TABLE `members` (
  `memberID` int(11) NOT NULL AUTO_INCREMENT,
  `banner` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`memberID`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;

标语表:

CREATE TABLE `banners` (
  `bannerID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `bannerTitle` varchar(255) DEFAULT NULL,
  `bannerSlug` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`bannerID`)
) ENGINE=MyISAM AUTO_INCREMENT=67 DEFAULT CHARSET=utf8; 
评论