im currently developing a small school project that involve creating a style survey for an interior design website to identify the type of room that a client wish to decorate.
i created a dynamic list that will return the list of option from the database which will show the options in the form of images.
when the user click one of the image that shows the type of room, the page should automatically bring the user to next question and save the option that the user has clicked.
my problem now is I cannot insert the option chosen by the user into my database, the image that the user has click.
below is my code
<?php
$dynamicList = "";
$sql = mysqli_query($con,"SELECT * FROM room ORDER BY room_date");
$roomCount = mysqli_num_rows($sql);
if ($roomCount > 0) {
while($row = mysqli_fetch_array($sql)){
$id = $row["room_id"];
$room_name = $row["room_name"];
$room_date = strftime("%b %d, %Y", strtotime($row["room_date"]));
$dynamicList .= '<ul class="room"><li><a href="#">
<center><a href="stylesurvey.php?id=' . $id . '"><img src="uploads/' . $id . '.jpg" alt="' . $room_name . '" width="170" height="170" /></a>
<h4>' . $room_name . '</h4>
</center>
</a>
</li>
</ul';
}
} else {
$dynamicList = "No room listed";
}
mysqli_close($con);
?>
<?php
if (isset($_POST["id"])) {
$id = $row["room_id"];
$room_name = $row["room_name"];
$survey_id = $row["survey_id"];
$room_id = $row["room_id"];
$date = strftime("%b %d, %Y", strtotime($row["date"]));
$sql = mysqli_query($con,"INSERT INTO survey (survey_id , room_id, user_id, room_name, date) VALUES('$survey_id','$room_id','$_SESSION[usr_name]','$room_name',now())") or die (mysql_error());
echo "Unable to insert data";
exit();
}
?>