How do I use a variable entered in a text box to be the search for the TinySong api? I tried using some variables but to no avail. Here is what I tried:
<?php
if(isset($_POST['submit'])) {
echo ' ', htmlspecialchars($_POST['something']);
}
?>
<?php
require_once 'tinysong.php';
$api_key = 'MY API KEY';
$query = '$something ';
$tinysong = new Tinysong($api_key);
$result = $tinysong
->search($query)
->execute();
echo "<pre>";
print_r($result);
echo "</pre>";
?>
I don’t understand why the text box’s value isn’t being queried. What do i have to change for it to work?? Thank You
You have no variable
$something. You have$_POST['something'], but unlessregister_globalsis on (which it shouldn’t be), you never populated$something. You therefore have nothing to query.Incidentally, you’ve also used single quotes here, which won’t cause the variable to be interpolated. Double quotes are needed for interpolation: