dtrnish3637 2016-09-25 17:25
浏览 40

如何在php和mysql中插入动态图像作为选项

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();
    }

?>
  • 写回答

1条回答 默认 最新

  • douxiangui5011 2016-09-25 17:35
    关注

    Here you pass values as a get method you need to use $_GET['id'] like this

    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 . '&room_name= .$room_name.'&room_date=.$room_date.'"><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($_GET["id"])) {
     $id = $_GET["room_id"];
     $room_name = $_GET["room_name"];
     $survey_id = $_GET["survey_id"];
     $date = $_GET["room_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();
    }
    
    ?>
    

    Now try this it should work

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题