Answer the question
In order to leave comments, you need to log in
$_SESSION variables in SQL query. How to insert?
There is a page with a form that prompts the user to select a dictionary. The selected value is passed to the $_SESSION['vocabulary_get'] variable, followed by a redirect to another page.
On another page, you need to display a selection of values (all words from the selected dictionary).
How to insert $_SESSION query into SQL?
include "connection1.php";
$arr = mysqli_query($connection, "SELECT DISTINCT `word` FROM `words` WHERE `vocabulary` = '$_SESSION['vocabulary_get']'");
echo '<div>';
while ($result1 = mysqli_fetch_array($arr))
{
echo ' <p>' . $result1['word'] . '</p>';
}
echo '</div>';
Answer the question
In order to leave comments, you need to log in
Just like any other
include "connection1.php";
$stmt = $connection->prepare("SELECT DISTINCT `word` FROM `words` WHERE `vocabulary` = ?");
$stmt->bind_param("s", $_SESSION['vocabulary_get']);
$stmt->execute();
$result = $stmt->get_result();
echo '<div>';
while ($row = mysqli_fetch_array($result))
{
echo ' <p>' . $row['word'] . '</p>';
}
echo '</div>';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question