Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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 参数错误,SQLSTATE[HY093]:参数编号无效:未定义参数_Php_Mysql_Forms_Parameters - Fatal编程技术网

Php 参数错误,SQLSTATE[HY093]:参数编号无效:未定义参数

Php 参数错误,SQLSTATE[HY093]:参数编号无效:未定义参数,php,mysql,forms,parameters,Php,Mysql,Forms,Parameters,所以我得到了SQLSTATE[HY093]:无效的参数号:当我试图提交表单时,没有定义参数。我有一个带有index.php文件的reservations文件夹,其中包含一个名为reservations.html.php的include文件,其格式为html 因此,我在reservations.html.php中的表单在填写完毕并且名字中有一个值时,将尝试将表单中的所有值发布到我在mysql中创建的reservations表中。下面是我在index.php中的代码 <?php // Edi

所以我得到了SQLSTATE[HY093]:无效的参数号:当我试图提交表单时,没有定义参数。我有一个带有index.php文件的reservations文件夹,其中包含一个名为reservations.html.php的include文件,其格式为html

因此,我在reservations.html.php中的表单在填写完毕并且名字中有一个值时,将尝试将表单中的所有值发布到我在mysql中创建的reservations表中。下面是我在index.php中的代码

<?php

// Edit or Replace this try/catch statement to work with the current PHT configuration
include '../includes/db.inc.php';

// Modify the If statement so the try only runs if the First Name field has been submitted AND the honeypot field is empty ''
if (isset($_POST['myfname'])) {
    $myFName = $_POST['myfname'];
    $myTour = $_POST['tour'];
    $myLName = $_POST['mylname'];
    $myEmail = $_POST['myemail'];
    // If the if statement is true, save each form field value as a variable. These variable values will be used in the thank you page.

    // And run the try/catch to attempt to insert data in the database. Modify the INSERT statement to write all the form filed values (except the honeypot) to the database.
    try
    {
        $sql = 'INSERT INTO reservations SET
          tour = :tour,
          fname = :fname,
          lname = :lname,
          email = :email';
        $s = $pdo->prepare($sql);
        $s->bindValue(':tour', $myTour);
        $s->bindValue(':myfname', $myFName);
        $s->bindValue(':mylname', $myLName);
        $s->bindValue(':myemail', $myEmail);
        $s->execute();
    }
    catch (PDOException $e)
    {
        $error = 'Error adding submitted joke: ' . $e->getMessage();
        include '../includes/error.html.php';
        exit();
    }
    // load the thank you page after the INSERT runs
    include 'success.html.php';
    // Add an else to load the initial page if the initial (line 19) if statement is false
} else {
    include 'reservations.html.php'; //Modify this to include the initial file for this folder
}

insert语句的语法已禁用,并且似乎是insert和update的混合。请尝试以下版本:

$sql = "INSERT INTO reservations (tour, fname, lname, email) ";
$sql .= "VALUES (:tour, :fname, :lname, :email)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':tour', $myTour, PDO::PARAM_STR);
$stmt->bindParam(':fname', $myFName, PDO::PARAM_STR);
$stmt->bindParam(':lname', $myLName, PDO::PARAM_STR);
$stmt->bindParam(':email', $myEmail, PDO::PARAM_STR);
$stmt->execute();
$stmt->close();
这里需要说明的是,SQL insert语句包含以下内容:

  • 插入到
    关键字中,后跟列列表
  • 然后是VALUES子句,后跟包含要插入的值的元组

还有一个
插入到。。。选择
,它使用SELECT语句提供值,但您没有使用此表单。

insert语句的语法已禁用,并且似乎是insert和update的混合。请尝试以下版本:

$sql = "INSERT INTO reservations (tour, fname, lname, email) ";
$sql .= "VALUES (:tour, :fname, :lname, :email)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':tour', $myTour, PDO::PARAM_STR);
$stmt->bindParam(':fname', $myFName, PDO::PARAM_STR);
$stmt->bindParam(':lname', $myLName, PDO::PARAM_STR);
$stmt->bindParam(':email', $myEmail, PDO::PARAM_STR);
$stmt->execute();
$stmt->close();
这里需要说明的是,SQL insert语句包含以下内容:

  • 插入到
    关键字中,后跟列列表
  • 然后是VALUES子句,后跟包含要插入的值的元组

还有一个
插入到。。。SELECT
,它使用SELECT语句提供值,但您没有使用此表单。

您的SQL语法可疑,但错误消息的原因是您正在定义
fname
lname
email
,但绑定到
myfname
mylname
myemail
。您的SQL语法可疑,但错误消息的原因是您正在定义
fname
lname
email
,但绑定到
myfname
mylname
myemail