Bas Bas - 1 year ago 138
PHP Question

Slim framework put post from other server

The code works fine on the same server.

My question is how can I do on one server and post the update?

So if I post on
, how can I achieve this? I am getting 404 page.

$app = new \Slim\Slim();

$app->put('/user/update/:id/', function( $id ) use( $app ){
global $connection;
$app->response()->header("Content-Type", "application/json");

if( $id && $id > 0 ){
$result = $connection->query( 'SELECT * FROM `users` WHERE id = '.(int)$id.' ;' );
$result = array();

if ($result) {
$post = $app->request()->put();
$result = $connection->query( "UPDATE `users` SET email = '".$_POST['email']."' WHERE id = $id;");
echo json_encode(array(
"status" => (bool)$result,
"message" => "User updated successfully"
echo json_encode(array(
"status" => false,
"message" => "User id $id does not exist"



<form action="" method="post">
<input type="text" name="email" value=""/>
<input type="hidden" name="_METHOD" value="PUT"/>
<input type="submit" value="Update user"/>

Bas Bas
Answer Source
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "email=".$_POST['email']."&_METHOD=put");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec ($ch);
    curl_close ($ch);

Need to send _METHOD=put

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download