I am using jquery autocomplete on a form and trying to do a simple echo of what is selected upon submitting a form entry to verify my data is being read correctly. I am receiving the following message:
Notice: Array to string conversion in C:\xampp\htdocs\New\search.php on line 4
Array
Search.php Contents:
<?php
$dest_name = $_GET["dest_name"];
echo ["dest_name"];
?>
Html contnts:
<body>
<form method="GET" action="search.php">
<div>
<input type="text" id ="destination" name="dest_name"/>
</div>
</form
</body>
autocomplete script
var destinations = [
{value: "49 Degrees North Ski Area",label: "49 Degrees North Ski Area",id: "1"},
{value: "Afton Alps",label: "Afton Alps",id: "2"},
{value: "Al Quaal Recreation Ski Area",label: "Al Quaal Recreation Ski Area",id: "3"},
{value: "Alpental",label: "Alpental",id: "4"},
{value: "Alpine Meadows",label: "Alpine Meadows",id: "5"},
];
$(document).ready(function() {
$("#destination").autocomplete({
source: destinations,
focus: function(event, ui) {
$("#destination").val(ui.item.label);
return false;
},
select: function(event, ui) {
$("#destination").val(ui.item.label);
$("#dest_id").val(ui.item.id);
return false;
}
});
$('#button').click(function() {
alert($("#dest_id").val());
});
});
In line 4 use have displayed the array index instead of that you have to echo the variable which you have declared in line 3.i.e.,
echo $dest_name;