I am a junior software developer. I want to understand how webservice works? And i have a database and i have a table which includes my datas row by row. Now ı want to update my inserted table via CURL. But i can not get current values into update table.
<?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);
}
?>
My expected result is to see the current values my current values in the table before update but i can not take them in.