I have two tables:
- USERS (id primary-key auto-increment, username,email_id, password)
- QUESTIONS (id primary-key auto-increment , type, question, date, time)
if a user named TINA(id 3) logs in and posts a question, her question should be saved in the table QUESTIONS with her respective id i.e 3. How can this be achieved?
<div id="content">
</br>
<form action="" method="post">
<center> <h3> <font color="green"> Ask a new question:
<select name="type" required>
<option value="" disabled selected> Select the type of question </option>
<option value="technical"> Technical </option>
<option value="entertainment"> Entertainment </option>
<option value="fashion"> Fashion </option>
<option value="food"> Food </option>
<option value="education"> Education </option>
<option value="lifestyle"> Lifestyle </option>
<option value="relationships"> Relationships </option>
<option value="health"> Health </option>
<option value="random"> Random </option>
</select>
</font> </h3>
<textarea rows="3" cols="100" style="resize:none" placeholder="Please type your question here..." name="ques" required></textarea><br>
<input type="submit" value="POST" name="POST" align="middle">
</center>
</form>
<?php
if(isset($_POST['POST']))
{
$type=$_POST['type'];
$ques=$_POST['ques'];
$date = strftime("%B %d, %Y");
$time = strftime("%r");
$sql="INSERT INTO questions (type,question,date,time) VALUES ('$type', '$ques', '$date', '$time')";
$query = mysqli_query($conn, $sql);
if(isset($_SESSION['id']))
{
echo "<div class='boxtype'>";
echo strtoupper($type);
echo "</div>";
echo "<div class='boxtime'>";
echo '['.$date.']'.' '.'['.$time.']';
echo "</div>";
echo "<div class='box'>";
echo "<font color='red'>".'<b>'.'<i>'.'<u>';
echo strtoupper($_SESSION['user']);
echo '</u>'.'</i>'.'</b>'.'</font>';
echo ':'.' '.$ques;
echo "</div>";
}
}
</div>