<?php require_once('connection.php');
session_start();
if (isset($_POST['Submit']))
{
$answ = $_POST['answ'];
$email = $_SESSION['email'];
$insert = "INSERT INTO answerList (answ,queID,email) SELECT questionList.queID FROM questionList " ;
$result = mysqli_query($con, $insert);
if (!$result) {
echo "<script>alert('ERROR !!!!! '); location='faq.php';</script>";
}
else {
echo "<script>alert('Successful Post'); location='faq.php'; </script>";
}
}
?>
I have 3 table table 1: users(email, password) table 2: question(questionID, questionContent, email) table 3: answer(answerID, answerContent, questionID, email)
how can i connect questionID into table 3? i already do the login and add question sql . but how can i add the answer to current question with logged email?
You could use <input type='hidden' name='questionId' value='<?php echo $value>'>
For each question you'll have to set $value to the questionID.
When the answer is submited you'll do:
if (isset($_POST['Submit']))
{
$answ = $_POST['answ'];
$email = $_SESSION['email'];
$questionId = $_POST['questionId'];
$insert = "INSERT INTO `answerList`(`answer`, `email`, `questionID`) VALUES ('$answ','$email','$questionId[value-3]')" ;
$result = mysqli_query($con, $insert);
if (!$result) {
echo "<script>alert('ERROR !!!!! '); location='faq.php';</script>";
}
else {
echo "<script>alert('Successful Post'); location='faq.php'; </script>";
}
}