*quick_searches.php
This code items that similar to a search done on a previous page. Then is supposed to save the specific brand listed to car.
<?php include 'header.php'; ?> <h1>Search Page</h1> <p>Could change to OR for broadness</p> <div class="article-container"> <?php if (isset($_POST['submit-search'])){ $time = mysqli_real_escape_string($conn, $_POST['time']); $brand = mysqli_real_escape_string($conn, $_POST['brand']); $cars = mysqli_real_escape_string($conn, $_POST['cars']); $location = mysqli_real_escape_string($conn, $_POST['location']); $sql = "SELECT * FROM classic_cars WHERE time LIKE'%$time%' AND brand LIKE '%$brand%' AND cars LIKE '%$cars%'AND location LIKE '%$location%'"; $result = mysqli_query($conn, $sql); $queryResult = mysqli_num_rows($result); echo "There are ".$queryResult." results!"; if ($queryResult > 0) { while ($row = mysqli_fetch_assoc($result)){ echo '<a href="test.php?car = '.$row['brand'].'"> <h3>'.$row['brand'].'</h3></a> <p>'.$row['time'].'</p> <p>'.$row['brand'].'</p> <p>'.$row['cars'].'</p> <p>'.$row['location'].'</p> '; } } else { echo "There are no results matching your search!"; } } ?> </div>
test.php
This section of code is supposed to get car = ‘.$row[‘brand’].’ from quick_searches.php and display it.
<?php echo $_GET['car']; ?>
Advertisement
Answer
So your URL has spaces around the parameter values – these have been URL Encoded to %20.
If you url_decode()
the URL you’ll see:
localhost:8080/classiccars/test.php?car = Ford
If you can update the URL to not have those spaces that would be preferable.
Alternatively try requesting $_GET['car ']
rather than $_GET['car']
and be sure to trim()
your value returned to take the space away from the beginning.
Generally much preferable to not have spaces in a URL if you don’t need them though and have control to change things.