Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:未定义参数_Php_Mysql_Pdo - Fatal编程技术网

Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:未定义参数

Php 警告:PDOStatement::execute():SQLSTATE[HY093]:无效参数编号:未定义参数,php,mysql,pdo,Php,Mysql,Pdo,我试图继续学习本教程,但对它做了一点修改(只需删除地址)。然而,在我自己纠正了一些错误之后,我对这一点很感兴趣 我的HTML和PHP代码如下 <?php if ( empty( $_POST ) ) { ?> <h1>PCReviews - Registration</h1> <form name="registration" action="registration" method="POST"> <label for 'user

我试图继续学习本教程,但对它做了一点修改(只需删除地址)。然而,在我自己纠正了一些错误之后,我对这一点很感兴趣

我的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>";
}
}


?>

PCR审查-注册
用户名:
密码:
名字:
姓:
电邮:

登记
但是,我收到如下错误:

<?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中未定义参数


谢谢:)

为什么你要调用
$query->execute
两次?而且肯定
:first\u Name
不是
:first\u Name
老实说,我只是在学习教程,我是PHP的新手,所以我无法证明为什么有两次执行。我想不应该有?谢谢@u_mulder解决了这个问题<代码>执行()运行查询。无需运行两次:)