I have a form (called suggestions) on my site that users fill in and submit. The data from the form is pulling through properly however I want to extract the email of the user too when they submit - this data is currently in the 'users' table (user will have given this info on sign up) in the database and I'm not sure how to access it?
Here's what I have so far:
$table = 'suggestions';
$id = (isset($_SESSION['u_id']) ? $_SESSION['u_id'] : null);
$email =
$optionOne = '';
$optionTwo = '';
$suggestions = selectAll($table);
if (isset($_POST['new-suggestion'])) {
global $conn;
$id;
$email;
$optionOne = $_POST['optionOne'];
$optionTwo = $_POST['optionTwo'];
$sql = "INSERT INTO $table (user_id, email, option_1, option_2) VALUES (?, ?, ?, ?)";
if (!empty($optionOne) && !empty($optionTwo)) {
$stmt = $conn->prepare($sql);
$stmt->bind_param('ssss', $id, $email, $optionOne, $optionTwo);
$stmt->execute();
} else {
echo "All options must be entered";
}
}
User ID is extracted via session so I'm thinking I could use this to get their email? Not sure what the '$email' variable should equal to get me this.