参数数量无效:绑定变量的数量与令牌的数量不匹配 - php 错误

2023-12-06

运行以下代码时,我基本上收到以下错误:

无法运行查询:SQLSTATE[HY093]:参数数量无效:绑定变量的数量与令牌数量不匹配

我是 php 新手,不确定为什么会收到此错误...我过去曾将这段代码用于 INSERT (而不是 UPDATE)语句,并且运行良好。

该代码是从另一个站点复制的,只是用作测试......

// First we execute our common code to connection to the database and start the session 
require("common.php"); 

 $id = $_GET[id];

// This if statement checks to determine whether the registration form has been submitted 
// If it has, then the registration code is run, otherwise the form is displayed 
if(!empty($_POST)) 
{

    // Ensure that the user has entered a non-empty password 
    if(empty($_POST['password'])) 
    { 
        die("Please enter a password."); 
    } 

    // Ensure that the user has entered a non-empty username 
    if(empty($_POST['confirmpassword'])) 
    { 
        // Note that die() is generally a terrible way of handling user errors 
        // like this.  It is much better to display the error with the form 
        // and allow the user to correct their mistake.  However, that is an 
        // exercise for you to implement yourself. 
        die("Please confirm your password."); 
    } 

     if ($_POST["password"] == $_POST["confirmpassword"]) {

    // An INSERT query is used to add new rows to a database table. 
    // Again, we are using special tokens (technically called parameters) to 
    // protect against SQL injection attacks. 
    $query = "UPDATE Staff SET password=:password, salt=:salt WHERE id=:id"; 

    // A salt is randomly generated here to protect again brute force attacks 
    // and rainbow table attacks.  The following statement generates a hex 
    // representation of an 8 byte salt.  Representing this in hex provides 
    // no additional security, but makes it easier for humans to read. 
    $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); 

    // This hashes the password with the salt so that it can be stored securely 
    // in your database.  The output of this next statement is a 64 byte hex 
    // string representing the 32 byte sha256 hash of the password.  The original 
    // password cannot be recovered from the hash. 
    $password = hash('sha256', $_POST['password'] . $salt); 

    // Next we hash the hash value 65536 more times.  The purpose of this is to 
    // protect against brute force attacks.  Now an attacker must compute the hash 65537 
    // times for each guess they make against a password, whereas if the password 
    // were hashed only once the attacker would have been able to make 65537 different  
    // guesses in the same amount of time instead of only one. 
    for($round = 0; $round < 65536; $round++) 
    { 
        $password = hash('sha256', $password . $salt); 
    }  

    try 
    { 
        // Execute the query to create the user 
        $stmt = $db->prepare($query); 
        $stmt->execute(array(
        ':password' => $password,
        ':salt' => $salt)); 


    } 
    catch(PDOException $ex) 
    { 
        // Note: On a production website, you should not output $ex->getMessage(). 
        // It may provide an attacker with helpful information about your code.  
        die("Failed to run query: " . $ex->getMessage()); 
    } 

    // This redirects the user back to the login page after they register 
    header("Location: login.php"); 

    // Calling die or exit after performing a redirect using the header function 
    // is critical.  The rest of your PHP script will continue to execute and 
    // will be sent to the user if you do not die or exit. 
    die("Redirecting to login.php"); 
} 
}

多谢, 乔


你错过了:id范围:

$stmt->execute(array(
    ':password' => $password,
    ':salt' => $salt,
    ':id' => $id
)); 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

参数数量无效:绑定变量的数量与令牌的数量不匹配 - php 错误 的相关文章

  • 如何使用 phpunit 运行单个测试方法?

    我正在努力运行一个名为testSaveAndDrop在文件中escalation EscalationGroupTest php with phpunit 我尝试了以下组合 phpunit EscalationGroupTest escal
  • 生成大随机数 php [重复]

    这个问题在这里已经有答案了 我想使用 PHP 生成一个包含 75 个字符的数字 我到处寻找 但一无所获 除了这个 http dailycoding com tools RandomNumber aspx http dailycoding c
  • 如何在响应ajax codeigniter后停止执行其他控制器

    我想知道如何在响应输出 json 数据后停止执行函数和涉及的其他控制器 就我这里的情况而言 我只是打电话test 函数于dashboard控制器 In dashboard构造函数将执行MY Login library In MY Login
  • 检查 PHP 中“@”字符后面的单词

    我现在正在制作一个新闻和评论系统 但是我已经在一个部分上停留了一段时间了 我希望用户能够在 Twitter 上引用其他玩家的风格 例如 用户名 该脚本看起来像这样 不是真正的 PHP 只是想象脚本 3 string I loved the
  • 如何从父类函数访问子类中定义的常量?

    我从 php net 看到这个例子 但 c MY CONST 仅在 5 3
  • 扩展蓝图类?

    我想覆盖timestamps 函数中发现Blueprint班级 我怎样才能做到这一点 e g public function up Schema create users function Blueprint table table gt
  • 如何处理数据库中的巨大结果集

    我正在设计一个多层数据库驱动的 Web 应用程序 SQL 关系数据库 用于中间服务层的 Java 用于 UI 的 Web 语言其实并不重要 中间服务层执行数据库的实际查询 用户界面只是要求某些数据 并不知道它是由数据库支持的 问题是如何处理
  • 将“php”作为 shell 脚本执行时的自定义 php.ini 文件

    我在跑php作为 shell 脚本 我不确定 shell脚本 是否正确 该文件以 usr bin php 这很好用 但 MongoDB 类没有正确加载php ini文件 具有extension mongo so 未使用 我该如何使用它tha
  • 如何在原则 2 迁移中删除外键

    我想在原则 2 迁移中删除外键 但没有 dropForeignKeyConstraint 有谁知道怎么丢掉吗 public function down Schema schema table schema gt getTable table
  • 无法在 Sqlite3 中添加默认值为 NULL 的 NOT NULL 列

    尝试将 NOT NULL 列添加到现有表时出现以下错误 为什么会发生这种情况 我尝试了 rake db reset 认为现有记录是问题所在 但即使重置数据库后 问题仍然存在 你能帮我解决这个问题吗 迁移文件 class AddDivisio
  • “使用未定义常量”注意,但该常量应该被定义

    共有三个文件 common php controller php 和 user php 文件 common php 如下所示 文件controller php看起来像 文件 user php 如下所示 执行脚本时 会给出通知 注意 使用未定
  • PHP 在输入流中使用 fwrite 和 fread

    我正在寻找将 PHP 输入流的内容写入磁盘的最有效方法 而不使用授予 PHP 脚本的大量内存 例如 如果可以上传的最大文件大小为 1 GB 但 PHP 只有 32 MB 内存 define MAX FILE LEN 1073741824 1
  • 在 PHP 中撤销 Google 访问令牌

    正如标题所示 我想以编程方式撤销授予的访问令牌 即在 PHP 中 我发现这个他们的网站 https developers google com identity protocols OAuth2WebServer tokenrevoke 但
  • MySQL 追加字符串

    How can I append a string to the end of an existing table value Let s say I have the table below And let s say that Mari
  • 在 PHP 中使用 phpseclib 时出现 RSA 问题

    我正在尝试在 phpseclib 中使用 RSA 实现 我认为在函数中执行一次代码并重新使用该函数会更容易 当我尝试向代码发送短信时 我收到一条错误消息 提示 解密错误 测试还让我意识到每次代码运行时密文都是不同的 所以我显然在那里做错了什
  • 表单计算器脚本基本价格未加载 OnLoad

    我的表单中有一个计算器来计算我的下拉选项选择 function select calculate on change calc input type checkbox calculate on click calc function cal
  • Doctrine EntityManager 清除嵌套实体中的方法

    我想用学说批量插入处理 http doctrine orm readthedocs org en latest reference batch processing html为了优化大量实体的插入 问题出在 Clear 方法上 它表示此方法
  • php,统计字符并删除超过140个字符的内容

    我需要一个 PHP 函数来计算短语的字符数 如果短语长度超过 140 个字符 则此函数应删除所有其他字符并在短语末尾添加三个点 例如我们有 message I am what I am and you are what you are et
  • 对具有混合类型值的数组进行数字排序

    我有一个像这样的混合数组 fruits array lemon Lemon 20 banana apple 121 40 50 然后申请sort 其功能如下 sort fruits SORT NUMERIC foreach fruits a
  • 无法显示 Laravel 欢迎页面

    我的服务器位于 DigitalOcean 云上 我正在使用 Ubuntu 和 Apache Web 服务器 我的家用计算机运行的是 Windows 7 我使用 putty 作为终端 遵循所有指示https laracasts com ser

随机推荐

  • FileStore 4.2.1 分步示例

    我想要上传 csv 文件 验证它 然后上传到现有模型中 然而 我正在使用 ATK4 2 1 发现 google 搜索到的示例代码要么缺少一些步骤 要么与版本 4 2 1 不相关 为此 在我的第一步中 我尝试混合和匹配代码 试图让文件存储启动
  • mod_rewrite:删除尾部斜杠(只有一个!)

    我使用 mod rewrite htaccess 来获得漂亮的 URL 我使用此条件 规则来消除尾随斜杠 或者更确切地说 通过 301 重定向重写到非尾随斜杠 URL 我这样做是为了避免重复内容 因为我喜欢没有尾随斜杠的 URL更好的 Re
  • 为什么 Canvas API 在循环中使用错误的颜色填充这些路径的部分内容?

    我创建了一个JSFiddle所有代码均处于活动状态并正在运行 相关JS在这里 const canvas document getElementById base const ctx canvas getContext 2d const cW
  • Lambda 未加载加密共享库

    我正在使用 AWS Lambda 中的加密库 我已在 Amazon Linux VM 中使用 pip 编译了该包 我已将包作为图层上传 不管怎样 每次我调用库时 我都会遇到一个根本不具有描述性的错误 Unable to import mod
  • 如何在Python PyQt5中将变量分配给工作线程?

    我使用pyqt5设计了一个GUI程序 我有一个主线程和一个工作线程 当 GUI 启动时 我会从用户那里获得一些输入 例如年龄 姓名 并且我想在工作人员中处理这些输入 例如我如何发送我使用的输入self ui firstname text 给
  • Silverlight:从 silverlight 控件创建图像

    是否可以从 silverlight 控件生成图像 以便该控件将自身及其内容渲染到图像中 以便我可以对图像进行相同的像素操作 在 Silverlight 2 中无法实现此目的 我见过人们通过将 XAML 发布到服务器来解决此限制 该服务器将使
  • 如何在 C# 中反序列化包含可变数量对象的 json 对象并将它们作为键值集合?

    如何反序列化以下 JSON 对象并获取 Dictionary 的集合 其中键 字符串 应该是方法名称 对象是 C 中的详细信息 methods password 2 title Password CustomerID type passwo
  • 使用 iText 将标题添加到 pdf

    如何使用 iText 5 0 5 将页眉添加到每个 PDF 页面 这涵盖在 iText 实践 第二版第 5 章 代码示例均可在线免费获取 尤其电影国家1 and 电影史2两者都处理page页眉和页脚 归结为使用PdfPageEvent实现
  • 拼写错误:找不到合适的拼写检查程序

    虽然功能aspell标配utils包 它似乎不适合我 我不断收到同样的错误 aspell love Error in aspell love No suitable spell checker program found 有什么想法吗 gt
  • 使用 GAS AT&T 指令计算引导扇区的填充长度?

    所以我想在引导扇区添加填充 比方说 目前只有一个无限循环 jmp 该扇区的长度需要为 512 字节 还有 神奇的数字0xaa55需要在最后添加 jmp skip 508 0 word 0xaa55 但是 如果我想打印一些内容 但不想计算所有
  • 如何在iOS Reachability中检测网络信号强度

    我正在 iOS 中创建一个新的旅行应用程序 该应用程序高度依赖于地图 并且将包含两个地图 当用户有较强的网络信号时 我的第一个地图将起作用 Apple 地图 我的第二张地图将在没有任何网络或信号非常低时使用 离线 地图框 为什么一个应用程序
  • 处理上传的文本文件后在 Google 云端硬盘中创建新文档

    我成功地将文本文件上传到谷歌云端硬盘 并且编写了一种方法 可以成功地将文本翻译为猪拉丁语 现在我尝试在 Google Drive 中创建一个新文档来输出翻译后的文本 但是 我总是收到消息 发生错误 当我检查我的云端硬盘时 我只有原始上传的文
  • AccountManager:如何让用户使用对话框选择帐户

    在 AccountManager 教程中记住您的用户 建议 如果有多个Account在数组中 你应该呈现一个 对话框要求用户选择一个 最好的方法是什么 我心中有一个解决方案 但如果社区中有其他好的示例 那么这似乎是一种可以由其他人共享和轻松
  • 为什么 Android Studio 3.0.0 在 APK 上设置 FLAG_TEST_ONLY?

    我已经通过 3 0 0 rcX 来自 Canary 渠道 到达 Android Studio 3 0 0 来自稳定渠道 当我启动一个全新的应用程序并构建它时 以下代码 应用程序内部 显示设置了 FLAG TEST ONLY 标志 Log e
  • Python 中 Pivot 和 Transpose 的组合

    我正在做一些文本分析 并且有一个看起来像这样的数据 TABLE 1 C1 C2 C3 A1 TEXT1 ANOTHER TEXT1 A2 TEXT1 ANOTHER TEXT1 B1 TEXT2 ANOTHER TEXT1 B2 TEXT2
  • 从多个 csv 文件中删除标题

    我有多个csv每天来自不同服务器的文件 这些文件很大 超过 200 MB 我必须删除所有这些的标题csv文件 并使用批处理文件将它们替换为所需的列标题 下面的代码可以很好地仅从一个文件中删除列标题 echo off set csv mycs
  • 获取经过的时间跨度的年、月、日 (DateTime)

    如何将日期时间选择器值中的年龄显示为年 月 日 例如 Datetimepicker value 1 11 2014 Today 1 12 2015 最终结果将是 1 年 0 个月 1 天 S 但得到这个结果不仅仅是减去DateTime Ye
  • void() 表达式的目的是什么?

    您不能声明void多变的 void fn void a ill formed 但这编译 void fn void a void object 什么是void 意思是 它有什么用 为什么是void a 格式不正确 同时void OK void
  • 从 ng-click 获取原始元素

    我的视图中有一个项目列表ng click附在他们身上 ul li img src team logoSmall alt title li ul 我正在处理点击事件foo在我的指令中起作用 传递 event作为对已单击对象的引用 但我得到了对
  • 参数数量无效:绑定变量的数量与令牌的数量不匹配 - php 错误

    运行以下代码时 我基本上收到以下错误 无法运行查询 SQLSTATE HY093 参数数量无效 绑定变量的数量与令牌数量不匹配 我是 php 新手 不确定为什么会收到此错误 我过去曾将这段代码用于 INSERT 而不是 UPDATE 语句