0

(I am no longer getting a parse error , just a blank apge with my header and nav bar- So please see that it is not a duplicate post)

I have the below code which will add a link to a details page. I am just not sure what I need to add to the details page to echo the "name" , I am stuck and really appreciate any assistance I can get. At the moment I just get a blank age when I click on the link from teh search results.

Search.php

<?php

$page='search';
include('header.php');
include ('navbar.php');
echo "<br>";
include ('connect.php');



if (isset ($_POST['search'])) { //the 'search' refers to the 'search' name=search on the index page and makes does something when the search is pushed.
$search = $_POST['search'];
$search = "%" . $search . "%"; // MySQL wildcard % either side of search to get partially matching results

// No wildcard if you want results to match fully
} else {

header ('location: index.php');

}



$stmt = $conn->prepare("SELECT * FROM test_db WHERE name LIKE :name ORDER BY name ASC"); // Use = instead of LIKE for full matching
$stmt->bindParam(':name', $search);
$stmt->execute();
$count = $stmt->rowCount(); // Added to count no. of results returned


if ($count >= 1) { // Only displays results if $count is 1 or more

echo "<div class='results_found'>";
echo $count;
echo " results found<br>";
echo "</div>";

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

echo "<div class='results'>";
echo "<div class='result_name'>";
echo "<b>Whisky Name:</b><br>";
echo "<a href='details.php?id={$row['lot_id']}' >{$row['name']}</a>;";
echo "</div>";
echo "</div>";
}

} else {
echo " Sorry no records were found";
}

?>

Details.php

<?php

$page='details';
include('header.php');
include ('navbar.php');
include ('connect.php');

if (isset($_GET['lot_id'])) {

    echo $row['name'];

?>
</html>
Jason
  • 1
  • 6
  • What is the line (in $_GET['lot_id']); meant to do? Should this not be. if(isset($_GET['lot_id']){ echo $row['name']; } – Adam Hull Jan 19 '17 at 20:56
  • What is your question exactly? – Ibu Jan 19 '17 at 21:26
  • My question is how do I echo the required reuslts after clicking on the link I have created on my search reults page. A search is carried out and the results are shown. I then want to be able to click on any of the results and get taken to a page which will give me more detials. At the moment i Just get a blank page. , with the code in the question. – Jason Jan 19 '17 at 21:31
  • I got my answe thanks. All sorted. – Jason Jan 19 '17 at 21:46

1 Answers1

0

Make sure to check if the GET variable is set: as simple as

if (isset($_GET['lot_id'])) {
  // DO something...
}

http://php.net/manual/en/function.isset.php

Kirby
  • 1
  • 1
  • So would this go into the results.php. I have tried the below and just get a blank page when I click the name and go get sent to the details.php .if (isset($_GET['lot_id'])) { echo $row['name']; } – Jason Jan 19 '17 at 20:59