I have several functions one of them is used for echo into select value. In this select value you have options chosen from database(in my case article headers). And I want this select value to be processed after submiting and then echo-ing article header and article content.
I am working with PHPMyAdmin
Function
Searches database for selected value while also checking UserID(Checking UserID works fine everywhere lese)
function SearchPost($UserID){
$conn = new PDO("mysql:host=$this->servername;dbname=$this->db", $this->usernameDB, $this->passwordDB);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("set names utf8");
if(isset($_POST['Filter_Edit'])&& array_key_exists('Search', $_POST)){
$st = $conn->prepare('SELECT PostName, PostContent FROM userposts WHERE PostName Like :PostName AND UserID Like :UserID');
$st->bindParam('PostName', $PostName);
$st->bindParam('UserID', $UserID);
$st->execute();
while($response = $st->fetch(PDO::FETCH_ASSOC)){
$Name = $UserPost['PostName'];
$YourPost = $UserPost['PostContent'];
echo "somethingsomethingsomethingsomethingsomething";
}
}
}
This is the site with the select tag and form
<form method="post">
<select class = "SelectEdit" name= "Filter_Edit">
<?php
$log->SearchPost($_SESSION['UserID_Session']);
?>
</select>
<button type="submit" name="Search" class="ButtonSearch">Vyhledat</button>
</form>
I don't know why it doesn't work and it doesn't print the echo in the function
Note: that Code is checked by script and there are no syntax errors
question from:https://stackoverflow.com/questions/65644858/function-that-is-used-for-searching-database-doesnt-work