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

Php 如何在获取后根据数据库的行向数据库插入值?

Php 如何在获取后根据数据库的行向数据库插入值?,php,pdo,Php,Pdo,我使用PDO从数据库中获取数据 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo " <table> <tr> <td>Name</td> <td>".$row["name"]."</td> </tr> <tr> <td>Subm

我使用PDO从数据库中获取数据

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
 echo "
  <table>
   <tr>
    <td>Name</td>
    <td>".$row["name"]."</td>
   </tr>

   <tr>
    <td>Submit url</td>
    <td><input type="text"><input type="submit"></td>
   </tr>
  </table>
 ";
}
while($row=$stmt->fetch(PDO::fetch_ASSOC)){
回声“
名称
“$row[“name”]”
提交url
";
}
我想根据数据库的行向数据库中插入一个值。我该怎么做?谢谢你的回答…

你是说更新

$sql = "UPDATE users SET name=?, surname=?, sex=? WHERE id=?";
$stmt= $pdo->prepare($sql);
$stmt->execute([$name, $surname, $sex, $id]);

您可以使用唯一id和
update/insert
ajax/post/get