I just started learning php, i have a long way to go but i really need help with this.
So I have a page where a logged in user can create tasks and that user can select the user for who the task is. I need to do an insert query where i'll need the ID of the person selected by the user who is logged in.
This is the code that's above my HTML:
$userId = $_SESSION['id'];
$Users = "SELECT * FROM users";
$Result2 = $db->query($Users);
if(isset($_POST['submit'])){
$project = $_POST['Project'];
$task = $_POST['task'];
$user = $_POST['User'];
$date = $_POST['date'];
$query = "INSERT INTO events (projectId, userId, name, date)
VALUES ('','', '$task', '$date')";
$result = $database->query($query);
echo "it worked";
}
This is the code in my HTML select tag, where the logged in user can select the person.
<?php
while ($row2 = mysqli_fetch_assoc($Result2)) {
$uid = $row2['id'];
$name = $row2['name'];
$lastName = $row2['lastname'];
echo "<option>" . $name . " " . $lastName . " " . $uid . "</option>";
}
?>
The problem is that I need to put the $uid variable, that's currently in the whileloop in my HTML select element, IN the first if statement above my HTML. I have tried everything but i cant seem to figure out how. It perfectly shows all of the users and their ID numbers, I just need to grab them and put them in my if statement.
<option value="$uid"> ....then it should be available in$_POST['whateveryourselectfieldiscalled']