PDOStatement中的警告:参数号无效[关闭](Warning in PDOStatement: Invalid parameter number [closed])

编程入门 行业动态 更新时间:2024-10-26 04:19:31
PDOStatement中的警告:参数号无效[关闭](Warning in PDOStatement: Invalid parameter number [closed])

也许你可以帮我解决这部分代码问题。 我试图让它工作,但当我尝试UPDATE总是显示这个错误:

警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:参数号无效:绑定变量的数量与/ home / ----- / public_html / soft / Admin / configuracion中的令牌数量不匹配第264行的.php

第264行是:

// Execute the query $stmt->execute();

下面是:

$stmt->bindParam(':page_meta_tag', $_POST['page_meta_tag']); $stmt->bindParam(':id', $_POST['id']);

这是我的代码:

<?php include '../include/update_config.php'; $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); $action = isset( $_POST['action'] ) ? $_POST['action'] : ""; if($action == "update"){ try{ $query = "update CONFIGURACION set id = :id, nombre_clinica = :nombre_clinica, direccion = :direccion, telefono_clinica = :telefono_clinica, titulo_clinica = :titulo_clinica, logo = :logo, page_meta_tag = page_meta_tag where id = 1"; $stmt = $conn->prepare($query); $stmt->bindParam(':nombre_clinica', $_POST['nombre_clinica']); $stmt->bindParam(':direccion', $_POST['direccion']); $stmt->bindParam(':telefono_clinica', $_POST['telefono_clinica']); $stmt->bindParam(':titulo_clinica', $_POST['titulo_clinica']); $stmt->bindParam(':logo', $_POST['logo']); $stmt->bindParam(':page_meta_tag', $_POST['page_meta_tag']); $stmt->bindParam(':id', $_POST['id']); // Execute the query $stmt->execute(); echo "Record was updated."; }catch(PDOException $exception){ //to handle error echo "Error: " . $exception->getMessage(); } } try { //prepare query $query = "select nombre_clinica, direccion, telefono_clinica, titulo_clinica, logo, page_meta_tag from CONFIGURACION where id = 1"; $stmt = $conn->prepare( $query ); //this is the first question mark $stmt->bindParam(1, $_REQUEST['id']); //execute our query $stmt->execute(); //store retrieved row to a variable $row = $stmt->fetch(PDO::FETCH_ASSOC); $id = $row['id']; $nombre_clinica = $row['nombre_clinica']; $direccion = $row['direccion']; $telefono_clinica = $row['telefono_clinica']; $titulo_clinica = $row['titulo_clinica']; $logo = $row['logo']; $page_meta_tag = $row['page_meta_tag']; }catch(PDOException $exception){ //to handle error echo "Error: " . $exception->getMessage(); } ?> <form class='form-horizontal' method='post' action='' enctype='multipart/form-data'> <fieldset> <legend><i class='icon32 icon-wrench'></i>Configuración General del Sistema</legend> <div class='control-group'> <label class='control-label' for='typeahead'>Nombre de la Clínica</label> <div class='controls'> <input type='text' class='span6 typeahead' name='nombre_clinica' value='<?php echo $nombre_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Dirección</label> <div class='controls'> <input type='text' class='span6 typeahead' name='direccion' value='<?php echo $direccion; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Número de Teléfono</label> <div class='controls'> <input type='text' class='span6 typeahead' name='telefono_clinica' value='<?php echo $telefono_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Viñeta de página web</label> <div class='controls'> <input type='text' class='span6 typeahead' name='titulo_clinica' value='<?php echo $titulo_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Logo Clínica</label> <div class='controls'> <input class='input-file uniform_on' id='fileInput' name='logo' type='file' /> <br /> <img style='max-height:80px;' src='../images/<?php echo $logo; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Meta tag del Software clínico</label> <div class='controls'> <input type='text' class='span6 typeahead' name='page_meta_tag' value='<?php echo $page_meta_tag; ?>' /> </div> </div> <div class='control-group'> <div class='controls'> <input type='hidden' name='id' value='<?php echo $id ?>' /><input type='hidden' name='action' value='update' /> <input type='submit' class='btn btn-primary' value='Actualizar configuracion' /> </div> </div> </fieldset> </form>

Maybe you can help me with this part of my code. I tried to make it works, but when I try to UPDATE always show me this error:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /home/-----/public_html/soft/Admin/configuracion.php on line 264

the line 264 is:

// Execute the query $stmt->execute();

Below of:

$stmt->bindParam(':page_meta_tag', $_POST['page_meta_tag']); $stmt->bindParam(':id', $_POST['id']);

Here is my code:

<?php include '../include/update_config.php'; $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); $action = isset( $_POST['action'] ) ? $_POST['action'] : ""; if($action == "update"){ try{ $query = "update CONFIGURACION set id = :id, nombre_clinica = :nombre_clinica, direccion = :direccion, telefono_clinica = :telefono_clinica, titulo_clinica = :titulo_clinica, logo = :logo, page_meta_tag = page_meta_tag where id = 1"; $stmt = $conn->prepare($query); $stmt->bindParam(':nombre_clinica', $_POST['nombre_clinica']); $stmt->bindParam(':direccion', $_POST['direccion']); $stmt->bindParam(':telefono_clinica', $_POST['telefono_clinica']); $stmt->bindParam(':titulo_clinica', $_POST['titulo_clinica']); $stmt->bindParam(':logo', $_POST['logo']); $stmt->bindParam(':page_meta_tag', $_POST['page_meta_tag']); $stmt->bindParam(':id', $_POST['id']); // Execute the query $stmt->execute(); echo "Record was updated."; }catch(PDOException $exception){ //to handle error echo "Error: " . $exception->getMessage(); } } try { //prepare query $query = "select nombre_clinica, direccion, telefono_clinica, titulo_clinica, logo, page_meta_tag from CONFIGURACION where id = 1"; $stmt = $conn->prepare( $query ); //this is the first question mark $stmt->bindParam(1, $_REQUEST['id']); //execute our query $stmt->execute(); //store retrieved row to a variable $row = $stmt->fetch(PDO::FETCH_ASSOC); $id = $row['id']; $nombre_clinica = $row['nombre_clinica']; $direccion = $row['direccion']; $telefono_clinica = $row['telefono_clinica']; $titulo_clinica = $row['titulo_clinica']; $logo = $row['logo']; $page_meta_tag = $row['page_meta_tag']; }catch(PDOException $exception){ //to handle error echo "Error: " . $exception->getMessage(); } ?> <form class='form-horizontal' method='post' action='' enctype='multipart/form-data'> <fieldset> <legend><i class='icon32 icon-wrench'></i>Configuración General del Sistema</legend> <div class='control-group'> <label class='control-label' for='typeahead'>Nombre de la Clínica</label> <div class='controls'> <input type='text' class='span6 typeahead' name='nombre_clinica' value='<?php echo $nombre_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Dirección</label> <div class='controls'> <input type='text' class='span6 typeahead' name='direccion' value='<?php echo $direccion; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Número de Teléfono</label> <div class='controls'> <input type='text' class='span6 typeahead' name='telefono_clinica' value='<?php echo $telefono_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Viñeta de página web</label> <div class='controls'> <input type='text' class='span6 typeahead' name='titulo_clinica' value='<?php echo $titulo_clinica; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Logo Clínica</label> <div class='controls'> <input class='input-file uniform_on' id='fileInput' name='logo' type='file' /> <br /> <img style='max-height:80px;' src='../images/<?php echo $logo; ?>' /> </div> </div> <div class='control-group'> <label class='control-label' for='typeahead'>Meta tag del Software clínico</label> <div class='controls'> <input type='text' class='span6 typeahead' name='page_meta_tag' value='<?php echo $page_meta_tag; ?>' /> </div> </div> <div class='control-group'> <div class='controls'> <input type='hidden' name='id' value='<?php echo $id ?>' /><input type='hidden' name='action' value='update' /> <input type='submit' class='btn btn-primary' value='Actualizar configuracion' /> </div> </div> </fieldset> </form>

最满意答案

您错过了:将查询更改为:

$query = "update CONFIGURACION set id = :id, nombre_clinica = :nombre_clinica, direccion = :direccion, telefono_clinica = :telefono_clinica, titulo_clinica = :titulo_clinica, logo = :logo, page_meta_tag = :page_meta_tag // <--- here it was missing where id = 1";

You missed a : Change the query to:

$query = "update CONFIGURACION set id = :id, nombre_clinica = :nombre_clinica, direccion = :direccion, telefono_clinica = :telefono_clinica, titulo_clinica = :titulo_clinica, logo = :logo, page_meta_tag = :page_meta_tag // <--- here it was missing where id = 1";

更多推荐

本文发布于:2023-08-06 19:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Warning   PDOStatement   Invalid   closed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!