我正在尝试在http://webdevelopingcat.com/creating-a-registration-page-with-php-and-pdo/上关注本教程,但稍微更改一下(只需删除地址)。但是在我自己纠正了一些错误后,我完全陷入了这个错误。
我的HTML和PHP代码如下;
<?php
if ( empty( $_POST ) ) {
?>
<h1>PCReviews - Registration</h1>
<form name="registration" action="registration" method="POST">
<label for 'username'>Username: </label>
<input type="text" name="username"/>
<label for 'password'>Password: </label>
<input type="password" name="password"/>
<label for 'first_name'>First name: </label>
<input type="text" name="first_name"/>
<label for 'surname'>Surname: </label>
<input type="text" name="surname"/>
<label for 'email'>Email: </label>
<input type="text" name="email"/>
<br/>
<button type="submit">Register!</button>
</form>
<?php
} else {$conn = new PDO("mysql:host=localhost;dbname=XXXX",'XXXX','XXXXX');
print_r ( '<p>Registration Succesfull!</p>' );
$form = $_POST;
$username = $form[ 'username' ];
$password = $form[ 'password' ];
$first_name = $form[ 'first_name' ];
$surname = $form[ 'surname' ];
$email = $form[ 'email' ];
$sql = "INSERT INTO UserAccounts ( username, password, first_name, surname, email ) VALUES ( :username, :password, :first_Name, :surname, :email )";
$query = $conn->prepare( $sql );
$query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname,':email'=>$email ) );
$result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname, ':email'=>$email ) );
if ( $result ){
echo "<p>Thank you. You have been registered</p>";
} else {
echo "<p>Sorry, there has been a problem inserting your details..</p>";
}
}
?>
但是我收到如下错误;
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未在第34行的/home/4328054/public_html/registration.php中定义
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未在第36行的/home/4328054/public_html/registration.php中定义
谢谢:)