I have looked at this answer enter link description here
but I am not able to make my code work, this is what i have in my selectcategory.php file. I want to have this variable $selectedcategory set up in this file. Echo command at the bottom is for testing purpose only.
My code:
<?php
include_once('config.php');
$query1 = mysqli_query($query, "SELECT category FROM `events` GROUP BY category");
echo "<select name'selectedcategory'>";
while ($row = mysqli_fetch_assoc($query1)){
echo "<option value='".$row['category']."'>".$row['category']."</option>";
}
echo "</select>";
$selectedcategory=$_POST['selectedcategory'];
echo $selectedcategory;
?>
Where do I make mistake? In other files I have taken variable by this POST method from INPUT or SELECT element with given name. In this file Error is on line 10 - UNDEFINIED VARIABLE, so where do I make mistake in getting it? Thank you in advance and if more clarification needed, please ask.
ps: I know my code has mistakes, but please concentrate only on getting the variable now. In other questions on this forum people just comment that my code is for example vulnerable for injections but no new information to the question itself or to prevent this injection (problem identified by commenter), I would like to prevent that. Identifing problem by commenter is great way of learning, but please than also provide some arguments why it is a problem or some links which relate to the problem.