2

我正在尝试对 mySql 数据库进行 PDO 更新。它没有显示任何错误,但也没有更新表格。

这是我使用的代码。用户从下拉列表中选择 POST 值。

 if (isset($_POST['changeLearningStyle'])){
 if (isset($_POST['learning'])){
 $var6 = $_POST['learning'];
 $stmt8 = $db->prepare("UPDATE users SET learningStyle = $var6 WHERE username = ?  AND     learningStyle = ?");
 $stmt8->execute(array($id, $learningStyle));
 $alert = '<div id="title1">Your learning style have been successfully updated</div>';
 }
} /**And the HTML looks  like this: **/
<form name="changeStyle" method="POST">
<div id="resetLearningStyle">
<div id="tab6">
 <h4 id="black">Learning Style</h4>
 <h5>Current Style: <?php echo($learningStyle) ?></h5>
 <select id="learning" name="learning" class="span3">
  <option value="">Select Style</option>
  <option value="Auditory">Auditory</option>
  <option value="Visual">Visual</option>
  <option value="Persuasive">Persuasive</option>
  <option value="Active">Active</option>    
  </select>
  </div>
  <input class="btn btn-inverse" type="submit" name="changeLearningStyle" value="Reset    Learning Style">
  </form>
 /**Table Structure **/

-- 表的表结构users

  CREATE TABLE `users` (
 `id` int(20) NOT NULL auto_increment,
 `fname` varchar(200) NOT NULL,
 `lname` varchar(200) NOT NULL,
 `username` varchar(200) NOT NULL,
 `password` varchar(200) NOT NULL,
 `country` varchar(200) NOT NULL,
 `rootLanugage` varchar(200) NOT NULL,
 `learningStyle` varchar(200) NOT NULL,
 `language` varchar(200) NOT NULL,
 `icon` varchar(200) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;

先感谢您!

4

1 回答 1

4

要使其显示错误,请在连接到数据库后立即添加以下代码:

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
于 2013-05-14T07:40:12.937 回答