gpt4 book ai didi

php - PDO 更新不工作

转载 作者:行者123 更新时间:2023-11-29 02:00:22 24 4
gpt4 key购买 nike

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

提前致谢!

最佳答案

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

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

关于php - PDO 更新不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16537558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com