Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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 PDO参数编号无效_Php_Mysql_Pdo_Mariadb - Fatal编程技术网

PHP PDO参数编号无效

PHP PDO参数编号无效,php,mysql,pdo,mariadb,Php,Mysql,Pdo,Mariadb,下面是我的代码,我无法解决此错误,我确实想把我所有的应用程序都放在这里,但是太长了,我不能,所以我把它放在驱动器里,我只知道编程的基本原理,我的应用程序根本不工作,所以没什么好担心的,这是我的完整应用程序,我知道你不需要所有的代码,只是相关的,但我不知道是什么错了,所以我不知道相关的是什么,我会在你的时候删除它必要时请帮忙谢谢大家 <?php //link files require 'db.php'; $message = ''; //get user input from the

下面是我的代码,我无法解决此错误,我确实想把我所有的应用程序都放在这里,但是太长了,我不能,所以我把它放在驱动器里,我只知道编程的基本原理,我的应用程序根本不工作,所以没什么好担心的,这是我的完整应用程序,我知道你不需要所有的代码,只是相关的,但我不知道是什么错了,所以我不知道相关的是什么,我会在你的时候删除它必要时请帮忙谢谢大家

<?php

 //link files

require 'db.php';
$message = '';
//get user input from the form

if (isset ($_POST['placa'])  &&  isset ($_POST['serialcarroria'])  &&  isset ($_POST['serialchasis'])  && isset ($_POST['serialmotor']) &&
 isset ($_POST['marca'])  &&  isset ($_POST['modelo'])  &&  isset ($_POST['year'])  && 
 isset ($_POST['color'])  &&  isset ($_POST['tipo'])  &&  isset ($_POST['uso'])  &&
 isset ($_POST['nropuestos'])  &&  isset ($_POST['nroejes'])  &&  isset ($_POST['capcarga'])  &&
 isset ($_POST['servicio']) ) {

 $placa = $_POST['placa'];
$serialcarroria = $_POST['serialcarroria'];
$serialchasis = $_POST['serialchasis'];
$serialmotor = $_POST['serialmotor'];
$marca = $_POST['marca'];
$modelo = $_POST['modelo'];
$year = $_POST['year'];
$color = $_POST['color'];
$tipo = $_POST['tipo'];
$uso = $_POST['uso'];
$nropuestos = $_POST['nropuestos'];
$nroejes = $_POST['nroejes'];
$capcarga = $_POST['capcarga'];
$servicio = $_POST['servicio'];  
      //SQL - add data to database
 $sql = 'INSERT INTO vehiculo(placa,serialcarroria,serialchasis,serialmotor,marca,modelo,year,color,tipo,uso,nropuestos,nroejes,capcarga,servicio) VALUES(:placa,:serialcarroria,:serialchasis,:serialmotor,:marca,:modelo,:year,:color,:tipo,:uso,:nropuestos,:nroejes,:capcarga,:servicio)';




  $statement = $connection->prepare($sql); //////<-PROBLEM ON THIS LINE//////
  if ($statement->execute([':placa' => $placa, ':serialcarroria' => $serialcarroria , ':serialchasis' => $serialchasis , ':serialmotor' => $serialmotor, ':marca' => $marca, ':modelo' => $modelo,':year' => $year, ':color' => $color, ':tipo ' => $tipo ,':uso ' => $uso  , ':nropuestos ' => $nropuestos , ':nroejes  ' => $nroejes  , ':capcarga ' => $capcarga  , ':servicio ' => $servicio]))  {
    $message = 'data inserted successfully';
  }

else {
  $message = 'Sorry, there has been a problem inserting your details..';
}

}

试试下面我的代码,看看它是否有效。让我知道你有什么错误

中,只需放置一个名为id的隐藏文本框,如下所示:

<form>
    <input type="hidden" name="id">
</form>

然后在PHP中执行以下操作:

<?php

$host = "localhost";
$user = "db_user";
$pass = "db_pass";
$db = "db_name";
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
    $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ];
    $connection = new PDO($dsn, $user, $pass, $opt);

    if (isset($_POST['placa'])) {
        //I don't see a reason to have all of those isset...just make it so that there's one field that 
        //is absolutely required and cannot be left empty and work from there.

        $statement = $connection->prepare("INSERT INTO vehiculo (id, placa, serialcarroria, serialchasis, serialmotor, marca, modelo, year, color, tipo, uso, nropuestos, nroejes, capcarga, servicio)
        VALUES (:id, :placa, :serialcarroria, :serialchasis, :serialmotor, :marca, :modelo, :year, :color, :tipo, :uso, :nropuestos, :nroejes, :capcarga, :servicio)");
        $statement->bindParam(':id', $id);
        $statement->bindParam(':placa', $placa);
        $statement->bindParam(':serialcarroria', $serialcarroria);
        $statement->bindParam(':serialchasis', $serialchasis);
        $statement->bindParam(':serialmotor', $serialmotor);
        $statement->bindParam(':marca', $marca);
        $statement->bindParam(':modelo', $modelo);
        $statement->bindParam(':year', $year);
        $statement->bindParam(':color', $color);
        $statement->bindParam(':tipo', $tipo);
        $statement->bindParam(':uso', $uso);
        $statement->bindParam(':nropuestos', $nropuestos);
        $statement->bindParam(':nroejes', $nroejes);
        $statement->bindParam(':capcarga', $capcarga);
        $statement->bindParam(':servicio', $servicio);

        $id = $_POST['id'];
        $placa = $_POST['placa'];
        $serialcarroria = $_POST['serialcarroria'];
        $serialchasis = $_POST['serialchasis'];
        $serialmotor = $_POST['serialmotor'];
        $marca = $_POST['marca'];
        $modelo = $_POST['modelo'];
        $year = $_POST['year'];
        $color = $_POST['color'];
        $tipo = $_POST['tipo'];
        $uso = $_POST['uso'];
        $nropuestos = $_POST['nropuestos'];
        $nroejes = $_POST['nroejes'];
        $capcarga = $_POST['capcarga'];
        $servicio = $_POST['servicio'];

        if ($statement->execute()) {
            echo 'data inserted successfully';
        } else {
            echo 'Sorry, there has been a problem inserting your details..';
        }
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}

$connection = null;
?>


您能在这里输入代码而不是驾驶吗?并且只有相关代码…1/您能在这里添加代码吗?2/第30行中未定义的参数是什么?3/您确定所有参数都返回值吗?尝试一些
var_dump(/*您的参数*/)
,以确保您得到的都是有价值的。4/尝试用
替换
isset
!空的
可能是为了避免空字符串或空值?好的,很抱歉我是新手,我会做得更好。您的问题是,
插入到的不是每个。。。(:placa,…)
占位符也对应于
execute()
中的
[':placa'=>…]
。一些或多个丢失或无关。我确实试过你的代码,这是我得到的PHP注意:未定义索引:第30行/create.PHP中的id$connection=new PDO($dsn,$username,$password,$options);}catch(PDOException$e){}这是我的变量connection的原始值在数据库中主键的名称是什么?它叫id吗?还是身份证?还是怎样另见更新代码@Gabrielandresm我的主键是id ok我要试试我刚刚意识到我错过了表格placa serialcarroria的那部分那是我的原始表格我必须做这样的东西吗?我把它放在下面,因为它太长了