簡體   English   中英

數據庫表未更新

[英]Database table is not updating

嗨,我正在嘗試更新我的tbl_jadwal,它表示成功,但是數據庫未更新,任何人都可以幫助我找到問題所在。 謝謝

 <?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 {

更新除圖像文件以外的所有數據

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

檢查更新結果

  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>";
            }

這是我的數據庫結構

在此處輸入圖片說明

您好只需先編寫簡單查詢並在其前面添加EXPLAIN。 例如:

EXPLAIN更新表集名稱=“ test”,其中id = 1;

該語句將顯示所有可能的錯誤。 這樣,您將能夠解決問題。

bindParam(':data', $data);替換bind_param() bindParam(':data', $data);

或者嘗試$stmt->execute(array(':data' => $data))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM