My HTML form:
<form action="lambda.php" method="post">
<label><input type="number" name="intfield" id="intfield"/></label>
<input type="submit" value="Go!"/>
</form>
Part of PHP code:
$hello = intval($_POST["intfield"]);
$client = LambdaClient::factory(array(
'version' => "latest",
'credentials' => array(
'key' => 'blurred',
'secret' => 'blurred'
),
'region' => 'us-west-2'
));
$response = $client->invoke([
'FunctionName' => 'helloworld2',
'InvocationType' => 'RequestResponse',
'Payload' => '{"key1":"$hello"}',
]);
echo($response['Payload']->__toString());
echo $hello;
Basically I want to type a number into the form of the HTML which is then given to the PHP code. The PHP file should send the number to a function in Lambda (Amazon Web Services).
My Lambda function and the PHP is fine. It works fine if I hardcode the number in the PHP like that:
'Payload' => '{"key1":"7"}',
But obviously I want to use it with a variable. The last echo in the PHP code shows the proper number though. Can you find a mistake in my PHP code? Thanks!
print_r($_POST)'{"key1":"$hello"}'print as a string not with value.'Payload' => json_encode(array('key1'=>$hello)),