Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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/59.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 - Fatal编程技术网

Php 使用PDO错误更新数据库

Php 使用PDO错误更新数据库,php,mysql,pdo,Php,Mysql,Pdo,我使用PDO使用以下方法将我的值更新到表中 表格 <form role="form" method="post" action="submitupdate.php" autocomplete="off"> <input class="update" type="text" name="fullname"></li> <input class="update" type="text" name="dob"></li> &

我使用PDO使用以下方法将我的值更新到表中

表格

<form role="form" method="post" action="submitupdate.php" autocomplete="off">
   <input class="update" type="text" name="fullname"></li>
   <input class="update" type="text" name="dob"></li>
   <textarea style="width:740px;height:220px;" class="update" type="text" name="intrested"></textarea></li>
   <textarea style="width:740px;height:220px;" class="update" type="text" name="description"></textarea></li>
</form>

有人能帮我吗

您在设置值之前正在执行查询。在执行查询时,您尝试使用的值尚未设置,因此没有任何数据可替换占位符

这应该起作用:

<?php

require('includes/config.php');
//if not logged in redirect to login page
if (!$user->is_logged_in()) {
    header('Location: login.php');
}
//define page title
$title = 'Members Page';
//include header template

try {

    $username = $_SESSION['username'];
    $fullname = $_POST['fullname'];
    $dob = $_POST['dob'];
    $intrested = $_POST['intrested'];
    $description = $_POST['description'];
    $sql = "UPDATE `members`   
   SET `fullname` = :fullname,
       `dob` = :dob,
       `inserted` = :inserted,
       `description` = :description 
 WHERE `username` = :username";



    $statement = $conn->prepare($sql);
    $params = array(
        ":username" => $username,
        ":fullname" => $fullname,
        ":dob" => $dob,
        ":inserted" => $intrested,
        ":description" => $description
    );
    $count = $statement->execute($params);

    $conn = null;        // Disconnect
} catch (PDOException $e) {
    echo $e->getMessage();
}

代码是否已完成

我看到$row,但您在哪里定义了$row

顺便说一句,您在设置值之前正在执行查询​​使用

将代码替换为以下内容:

<?php

require('includes/config.php');
//if not logged in redirect to login page
if (!$user->is_logged_in()) {
    header('Location: login.php');
}
//define page title
$title = 'Members Page';
//include header template

try {



    $sql = "UPDATE `members`   
   SET `fullname` = :firstname,
       `dob` = :dob,
       `inserted` = :inserted,
       `description` = :description 
 WHERE `username` = :username";


    $username = $_SESSION['username'];
    $fullname = $row['fullname'];
    $dob = $row['dob'];
    $intrested = $row['intrested'];
    $description = $row['description'];    


    $statement = $conn->prepare($sql);
    $statement->bindValue(":username", $username);
    $statement->bindValue(":fullname", $fullname);
    $statement->bindValue(":dob", $dob);
    $statement->bindValue(":inserted", $intrested);
    $statement->bindValue(":description", $description);
    $count = $statement->execute();

    $conn = null;        // Disconnect
} catch (PDOException $e) {
    echo $e->getMessage();
}

i get
SQLSTATE[HY093]:无效参数编号:未定义参数
进行了一些编辑检查我的问题有一些错误检查我的问题进行了一些编辑i get
SQLSTATE[HY093]:无效参数编号:未定义参数
进行了一些编辑检查我的问题如果已编辑问题以修复原始问题,则应提出新问题。请关闭此问题并再次提问,因为下面的答案不再适用于您所问的内容,我对您现在的实际问题感到困惑。
<?php

require('includes/config.php');
//if not logged in redirect to login page
if (!$user->is_logged_in()) {
    header('Location: login.php');
}
//define page title
$title = 'Members Page';
//include header template

try {

    $username = $_SESSION['username'];
    $fullname = $_POST['fullname'];
    $dob = $_POST['dob'];
    $intrested = $_POST['intrested'];
    $description = $_POST['description'];
    $sql = "UPDATE `members`   
   SET `fullname` = :fullname,
       `dob` = :dob,
       `inserted` = :inserted,
       `description` = :description 
 WHERE `username` = :username";



    $statement = $conn->prepare($sql);
    $params = array(
        ":username" => $username,
        ":fullname" => $fullname,
        ":dob" => $dob,
        ":inserted" => $intrested,
        ":description" => $description
    );
    $count = $statement->execute($params);

    $conn = null;        // Disconnect
} catch (PDOException $e) {
    echo $e->getMessage();
}
<?php

require('includes/config.php');
//if not logged in redirect to login page
if (!$user->is_logged_in()) {
    header('Location: login.php');
}
//define page title
$title = 'Members Page';
//include header template

try {



    $sql = "UPDATE `members`   
   SET `fullname` = :firstname,
       `dob` = :dob,
       `inserted` = :inserted,
       `description` = :description 
 WHERE `username` = :username";


    $username = $_SESSION['username'];
    $fullname = $row['fullname'];
    $dob = $row['dob'];
    $intrested = $row['intrested'];
    $description = $row['description'];    


    $statement = $conn->prepare($sql);
    $statement->bindValue(":username", $username);
    $statement->bindValue(":fullname", $fullname);
    $statement->bindValue(":dob", $dob);
    $statement->bindValue(":inserted", $intrested);
    $statement->bindValue(":description", $description);
    $count = $statement->execute();

    $conn = null;        // Disconnect
} catch (PDOException $e) {
    echo $e->getMessage();
}