Reputation: 107
Im trying to do a PDO update to mySql database. Its not showing any errors, but neither is it updating the table.
here is the code that im using. The user selects the POST value from a drop down list.
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 ;
Thank You in advance!
Upvotes: 1
Views: 2583
Reputation: 25935
To make it show errors, add this line of code right after connecting to the DB:
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Upvotes: 3