php - 将数据放入php和curl中的更新表中
问题描述
我是一名初级软件开发人员。我想了解网络服务是如何工作的?我有一个数据库,我有一个表,其中逐行包含我的数据。现在我想通过 CURL 更新我插入的表。但我无法将当前值放入更新表中。
<?php
require_once('index.php');
require("index.php");
if($_POST)
{
$id = ($_POST['id']);
$first_name = ($_POST['first_name']);
$last_name = ($_POST['last_name']);
$query=$first_name.'|'.$last_name;
$params=array(
'action' => "UPDATESINGLE",
'query' => $query
);
$postData='';
foreach($params as $k => $v){
$postData .= $k . '='.$v.'&';
}
rtrim($postData, '&');
if(is_array($postData)){
$count=count($postData);
}else{
$count=0;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/webservice/service.php");
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
print_r($response);
}
$query = $myPDO->query("SELECT * FROM users",PDO::FETCH_ASSOC);
echo '<table class="table" border="2">
<tr>
<th scope="col">Row Id</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Update</th>
<th scope="col">Delete</th>
</tr>';
foreach ($query as $row)
{
echo '<tr>
<td>'.$row["user_id"].'</td>
<td>'.$row["first_name"].'</td>
<td>'.$row["last_name"].'</td>
<td><a href="?do=update&id='.$row["user_id"].'">Update</a>
</td>
<td><form action="" method="post">
<input type="submit" name="" value="Delete">
</form>
</td>
</tr>';
}
echo '</table>';
if(isset($_GET['do']))
{
$data=explode('|',$query);
$username=$data[0];
$usersurname=$data[1];
$event=$_GET['do'];
if($event == "update")
{
echo '<table class="table" border="2">
<form action="" method="post">
<input type="text" name="first_name" value="'.$username.'">
<input type="text" name="last_name" value="'.$usersurname.'">
<input type="submit" name="" value="Update">
</form>
';
echo '</table>';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/webservice/service.php");
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
print_r($response);
}
?>
我的预期结果是在更新之前在表中查看我当前值的当前值,但我无法接受它们。
解决方案
推荐阅读
- php - 使用 PHP 将 HTML 表单连接到 SQL 数据库
- python - Pandas 数据框新列 from where 逻辑(接收关键字错误)
- javascript - 将基于 fetch 的函数转换为之前返回 promise 的异步函数
- python - 使用 CreateProcess 从 C++ 调用 Python 文件
- delphi - 对引用单元实现中的单元的依赖
- java - 如何在 Java 中读取和打印 PKI 属性,例如 Common Name
- javascript - 如何导出没有大括号的扩展类?(节点 JS)
- java - 处理继承时的HQL分组问题
- ssl - Hyperledger Fabric - Peer 无法使用 Mutual TLS 连接到(筏)Orderer
- xml - python3.5:如何使用 python-docx 库添加复选框?