Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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/65.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 准备语句返回未定义的索引错误_Php_Mysql - Fatal编程技术网

Php 准备语句返回未定义的索引错误

Php 准备语句返回未定义的索引错误,php,mysql,Php,Mysql,我真的很难破解这个坚果 MySQL数据库由以下列名称组成:id、存储、结果 我在表格里有一个按钮。单击“选择”按钮时,columnname记录应更新为+1。每次单击按钮时,我都会收到错误信息: 注意:第8行的/Applications/MAMP/htdocs/practiceProject/updaterecords.php中未定义的索引:id 更新成功 我在stackoverflow上读到这是因为我没有得到id的值。因此我添加了$id=$\u POST['id'];,但仍然得到同样的错误 有人

我真的很难破解这个坚果

MySQL数据库由以下列名称组成:id、存储、结果

我在表格里有一个按钮。单击“选择”按钮时,columnname记录应更新为+1。每次单击按钮时,我都会收到错误信息:

注意:第8行的/Applications/MAMP/htdocs/practiceProject/updaterecords.php中未定义的索引:id 更新成功

我在stackoverflow上读到这是因为我没有得到id的值。因此我添加了$id=$\u POST['id'];,但仍然得到同样的错误

有人知道这里出了什么问题吗

index.php

updaterecords.php


绑定参数应以:id开头 还要确保$id=$\u POST['id'];正在张贴

<form action="updaterecords.php" method="post">
<!-- test the id -->
<input type="hidden" value="333" name="id" />
   <button type="submit" name="selectstore" >Select</button>
   <!-- removed php include don't need it here -->
  <button type="button" data-dismiss="modal">Close</button>
</form>
updaterecords.php


您没有为您的id发布值。 php脚本如何知道要更新哪一行?
html中没有输入字段或类似内容,因此未定义$\u POST['id'.

不需要以冒号开头占位符。您也不必使用命名占位符,例如?是一个完全可以接受的占位符。您好。非常感谢你的回答。我只是在测试你的代码,但是我的数据库仍然没有用+1更新。但是当我单击select按钮时,我没有得到任何错误,只是updaterecords.php上的一个空白页面。如果我使用id号,我的查询在myPhpAdmin中运行良好。Fx:updatestores SET records=records+1,其中id=333;你应该在OP的问题下删除你的评论。我现在删除了你表单中的php include,也许这就是问题的原因。非常感谢你的帮助。我得到一个空白页,数据库中没有更新。但至少我没有像以前那样犯错误。我会接受你的答案,等我弄明白剩下的,我就可以写在这里了。现在你们在我的问题上花了很多时间,所以我要告诉你们:-你们的表单有一个name=id的字段吗?如果没有$_POST['id']将永远不会被填充。感谢您的评论。此问题表单中的我的字段,或当我插入数据时,或?您上面显示的表单没有名为id的输入,因此未设置$u POST['id']。你为什么要在表格的中间包含一个文件?谢谢你的回答。在这个项目中,我在大约25个不同的文档中使用了$u POST['id']。除了这个,一切都正常。
<?php error_reporting(E_ALL); ini_set('display_errors', 1);

if (mysqli_connect_errno()) { echo "Error: no connexion allowed : " . mysqli_connect_error($mysqli); } 
?>
<?php
include 'dbconnection.php';

if(isset($_POST['selectstore'])) {
$id = $_POST['id']; // Line 8

    $stmt = $mysqli->prepare("UPDATE stores SET records = records + 1 WHERE id= ?");

    $stmt->bind_param('i', $id);   

    if ($stmt->execute()) { 
        $success = true;
    }

    $stmt->close();

    $mysqli->close();   
    if($success) {
        echo "Updated Succesfull";
    } else {
        echo "Failed: " .  $stmt->error;
      }
    }

?>
<form action="updaterecords.php" method="post">
<!-- test the id -->
<input type="hidden" value="333" name="id" />
   <button type="submit" name="selectstore" >Select</button>
   <!-- removed php include don't need it here -->
  <button type="button" data-dismiss="modal">Close</button>
</form>
        <?php error_reporting(E_ALL); ini_set('display_errors', 1);

        if (mysqli_connect_errno()) { echo "Error: no connexion allowed : " . mysqli_connect_error($mysqli); } 
        ?>
        <?php
        include 'dbconnection.php';

        if(isset($_POST['selectstore'])) {
        $id = $_POST['id']; // Line 8

            $stmt = $mysqli->prepare("UPDATE stores SET records = records + 1 WHERE id = :id");

                $stmt->bindParam(':id', $id);   

            if ($stmt->execute()) { 
                $success = true;
            }

            $stmt->close();

            $mysqli->close();   
            if($success) {
                echo "Updated Succesfull";
            } else {
                echo "Failed: " .  $stmt->error;
              }
            }

        ?>