我的本地服务器给我以下错误,我不知道为什么
(!)注意:未定义变量:第20行的C:\ wamp \ www \ house \ profile_query.php中的pdo
(!)致命错误:未捕获的错误:在第20行的C:\ wamp \ www \ house \ profile_query.php中的null上调用成员函数prepare()
(!)错误:在第20行的C:\ wamp \ www \ house \ profile_query.php中,在null上调用成员函数prepare()
这是我的连接和更新代码:
<?php
$db_username = 'root';
$db_password = '';
//check if submit button is clicked
If(isset($_POST['save'])){
try {
$conn = new PDO( 'mysql:host=localhost;dbname=urbane_casa', $db_username, $db_password );
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$sql = "UPDATE users SET companyname = :companyname,
usernsme = :usernsme,
phone = :phone,
website = :website,
country = :country
WHERE user_id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':companyname', $_POST['companyname'], PDO::PARAM_STR);
$stmt->bindParam(':usernsme', $_POST['$usernsme'], PDO::PARAM_STR);
$stmt->bindParam(':phone', $_POST['phone'], PDO::PARAM_STR);
// use PARAM_STR although a number
$stmt->bindParam(':website', $_POST['website'], PDO::PARAM_STR);
$stmt->bindParam(':country', $_POST['country'], PDO::PARAM_STR);
$stmt->bindParam(':user_id', $_POST['$id'], PDO::PARAM_INT);
$stmt->execute();
echo ' SAVED';
}catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
$conn = null;
}
?>
请帮助