Reputation: 5844
I am using malert.in as sms gateway. I want to send the details the user entered, but in place of name $name is sent.
<!DOCTYPE HTML>
<html>
<head>
</head>
<html>
<body>
<form action='sms.php' method='post'>
<div>
<label for='name'>Name</label>
<input type='text' name='name' id='name'/>
</div>
<div>
<label for='pnr'>Pnr</label>
<input type='text' name='pnr' id='pnr'/>
</div>
<div>
<input type='submit' name='send' value='send'/>
</div>
</form>
</body>
</html>
<?php
if(isset($_POST['send']))
{
$name = $_POST['name'];
$pnr = $_POST['pnr'];
header('Location:http://malert.in/new/api/api_http.php?username=uname&password=pass&senderid=Alerts&to=7098765438,9454321121&text=$name%20$pnr%20success&route=Transaction&type=text&datetime=2015-01-23%2015%3A15%3A14');
}
?
Where is the mistake? I checked everything.
Upvotes: 1
Views: 192
Reputation: 63580
Variables are not expanded inside single quoted strings such as 'text=$name'
, but only inside double quoted strings like "text=$name"
. Additionally, if you need to append the string to a URL, you need to also escape it appropriately with urlencode()
. You could do something like:
header('Location:' .
'http://malert.in/new/api/api_http.php' .
'?username=uname' .
'&password=pass' .
'&senderid=Alerts' .
'&to=7098765438,9454321121' .
'&text=' . urlencode("$name $pnr success") .
'&route=Transaction' .
'&type=text' .
'&datetime=' . urlencode('2015-01-23 15:15:14'));
Upvotes: 2
Reputation: 2856
Variables are not evaluated in single quotes. You need to either use double quotes, or add the individual string pieces together:
header('Location: ...&text='.$name.'%20$pnr%20success&route=Tra...');
Upvotes: 1