整天都在与这段代码作斗争,大部分错误都被敲定了,但现在我收到了这个错误消息
致命错误:在第 26 行的 /home/jsnow/public_html/registration.php 中的非对象上调用成员函数 prepare()
这是我的代码:
<?php
if(isset($_POST['username']) && isset($_POST['password']))
{
$db =connect('********','*********');
if($db!=false)
{
register($db);
echo "User registered";
}
}
function connect($dbuser,$dbpassword)
{
try{
$db = new PDO('mysql:host=localhost;dbname=jsnow_login', '*******' , '*********');
return $db;
}catch(PDOException $e){
echo $e;
return false;}
}
function register($db)
{
$result_set = $pdo->prepare("INSERT INTO `users` (`username`, `password`)
VALUES (:username, :password)");
$result_set->execute(array(
':username' => $username, ':password' => $password
));
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="http://vps8383.***********.com/~jsnow/registration.php" method="post">
username:<input type="text" name="username"/>
password:<input type="password" name="password"/>
email<input type="text" name="e_mail"/>
<input type="submit"/>
</form>
</body>
</html>