PDO更新无法正常工作

时间:2013-05-14 07:37:40

标签: php mysql

我正在尝试对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 ;

提前谢谢你!

1 个答案:

答案 0 :(得分:3)

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

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);