简体   繁体   English

数据库表未更新

[英]Database table is not updating

Hi I'm trying to update my tbl_jadwal, it said success, but database is not updated, anybody can please help me finding where the problem is ? 嗨,我正在尝试更新我的tbl_jadwal,它表示成功,但是数据库未更新,任何人都可以帮助我找到问题所在。 Thankyou 谢谢

 <?php

    if (isset($_GET['id'])) {
        $ID = $_GET['id'];
    } else {
        $ID = "";
    }

    // create array variable to store category data
    $category_data = array();

    $sql_query = "SELECT Category_ID, Category_name 
            FROM tbl_category 
            ORDER BY Category_ID ASC";

    $stmt_category = $connect->stmt_init();
    if ($stmt_category->prepare($sql_query)) {
        // Execute query
        $stmt_category->execute();
        // store result 
        $stmt_category->store_result();
        $stmt_category->bind_result($category_data['Category_ID'],
            $category_data['Category_name']
        );

    }

    $sql_query = "SELECT Menu_image FROM tbl_jadwal WHERE Menu_ID = ?";

    $stmt = $connect->stmt_init();
    if ($stmt->prepare($sql_query)) {
        // Bind your variables to replace the ?s
        $stmt->bind_param('s', $ID);
        // Execute query
        $stmt->execute();
        // store result
        $stmt->store_result();
        $stmt->bind_result($previous_menu_image);
        $stmt->fetch();
        $stmt->close();
    }


    $stmt = $connect->stmt_init();
    if ($stmt->prepare($sql_query)) {
        // Execute query
        $stmt->execute();
        // store result
        $stmt->store_result();
        $stmt->fetch();
        $stmt->close();
    }


    if (isset($_POST['btnEdit'])) {

        $nama_lokasi = $_POST['nama_lokasi'];
        $category_ID = $_POST['category_ID'];
        $longitude = $_POST['longitude'];
        $latitude = $_POST['latitude'];
        $phone = $_POST['phone'];
        $email = $_POST['email'];
        $description = $_POST['description'];


        // get image info
        $menu_image = $_FILES['menu_image']['name'];
        $image_error = $_FILES['menu_image']['error'];
        $image_type = $_FILES['menu_image']['type'];

        // create array variable to handle error
        $error = array();




  // updating all data              


$sql_query = "UPDATE tbl_jadwal 
                        SET Nama_Lokasi = ? , Category_ID = ?, Latitude = ?, Longitude = ?, Phone = ?, Email = ?, Menu_image = ?, Description = ? 
                        WHERE Menu_ID = ?";

                $upload_image = 'upload/images/' . $menu_image;
                $stmt = $connect->stmt_init();
                if ($stmt->prepare($sql_query)) {
                    // Bind your variables to replace the ?s
                    $stmt->bind_param('ssssssss',
                        $nama_lokasi,
                        $category_ID,
                        $longitude,
                        $latitude,
                        $phone,
                        $email,
                        $upload_image,
                        $description,
                        $ID);
                    // Execute query
                    $stmt->execute();
                    // store result 
                    $update_result = $stmt->store_result();
                    $stmt->close();
                }
            } else {

updating all data except image file 更新除图像文件以外的所有数据

$sql_query = "UPDATE tbl_jadwal
                        SET Nama_Lokasi = ? , Category_ID = ?, 
                        Longitude = ?, Latitude = ?, Phone = ?, Email = ?, Description = ? 
                        WHERE Menu_ID = ?";

                $stmt = $connect->stmt_init();
                if ($stmt->prepare($sql_query)) {
                    // Bind your variables to replace the ?s
                    $stmt->bind_param('sssssss',
                        $nama_lokasi,
                        $category_ID,
                        $longitude,
                        $latitude,
                        $phone,
                        $email,
                        $description,
                        $ID);
                    // Execute query
                    $stmt->execute();
                    // store result 
                    $update_result = $stmt->store_result();
                    $stmt->close();
                }
            }

check update result 检查更新结果

  if ($update_result) {
                $error['update_data'] = " <span class='label label-primary'>Success update</span>";
            } else {
                $error['update_data'] = " <span class='label label-danger'>failed update</span>";
            }

This my database structure 这是我的数据库结构

在此处输入图片说明

Hi Just write the simple query firstly and add EXPLAIN before it. 您好只需先编写简单查询并在其前面添加EXPLAIN。 For example: 例如:

EXPLAIN update table set name='test' where id=1; EXPLAIN更新表集名称=“ test”,其中id = 1;

This statement will show all the possible error. 该语句将显示所有可能的错误。 In this way you will be able to resolve the problem. 这样,您将能够解决问题。

replace bind_param() with bindParam(':data', $data); bindParam(':data', $data);替换bind_param() bindParam(':data', $data);

or try $stmt->execute(array(':data' => $data)) 或者尝试$stmt->execute(array(':data' => $data))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM