i've been on it for 2 days. can someone help
search.php
************************************************** **************
<form method="post" action="search.php">
<select id="name" name="name">
<option value="entertainment">Entertainment</option>
<option value="romance">Romance</option>
</select>
</br>
<input class="w3-input" type="text" id="location" name="location" placeholder="Location">
</br>
<input type="text" id="city" name="city" placeholder="City">
</br>
<select id="state" name="state">
<option value="newyork">new york</option>
<option value="texas">texas</option>
<option value="london">london</option>
</select>
</br>
<input type="submit" name="submit" value="Search">
</form>
************************************************** **************
i want to pass the value to getPublishedPosts()
public_functions.php
************************************************** ****************
// form variables from users
$name = "";
$type = "";
$area = "";
$city = "";
$state = "";
/* - - - - - - - - - -
- Admin users actions
- - - - - - - - - - -*/
// if user clicks the search button
if (isset($_POST['submit'])) {
getPublishedPosts($_POST);
}
/* * * * * * * * * * * * * * *
* Returns all published posts
* * * * * * * * * * * * * * */
function getPublishedPosts($request_values) {
global $conn, $name, $type, $area, $city, $state;
$name = $request_values['name'];
$type = $request_values['type'];
$area = $request_values['area'];
$city = $request_values['city'];
$state = $request_values['state'];
$sql = "SELECT id, area, city, file_name FROM search WHERE name LIKE '%".$name."%' AND type LIKE '%".$type."%' AND area LIKE '%".$area."%' AND city LIKE '%".$city."%' AND state LIKE '%".$state."%'";
$result = mysqli_query($conn, $sql);
// fetch all posts as an associative array called $posts
$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
$final_posts = array();
foreach ($posts as $post) {
$post['topic'] = getPostTopic($post['id']);
array_push($final_posts, $post);
}
return $final_posts;
}
************************************************** **************************
to display the result gotten from database on index.php
index.php
************************************************** ***************
<?php foreach ($posts as $post): ?>
<a href="single_post.php?post-slug=<?php echo $post['slug']; ?>">
<div class="w3-third">
<div class="w3-card w3-btn">
<img src="<?php echo BASE_URL . '/static/images/' . $post['image']; ?>" class="post_image" alt="">
<h5><?php echo $post['area'] ?><h5/>
<h3><?php echo $post['city'] ?><h3/>
</div>
</div>
</a>
<?php endforeach ?>
************************************************** **********