0

Trying to fetch the user's email who submitted this form (the email is stored in a different table in the database). The query executes however shows only the word 'Array' where I want the email to show. Does anyone know what I need to add/how to alter my query to make this happen?

$table = 'suggestions';
$id = (isset($_SESSION['u_id']) ? $_SESSION['u_id'] : null);

if ( NULL !== $id) {
  $stmt = $pdo->prepare("
SELECT email 
  FROM users 
 WHERE u_id=$id");
  $stmt->execute();
  $email = $stmt->fetch();
}


$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";
  }
}
Strawberry
  • 33,750
  • 13
  • 40
  • 57
ARick12
  • 35
  • 5

0 Answers0