簡體   English   中英

如何從插入的數據中刪除“到MySQL數據庫

[英]How to delete " from inserted data to MySQL database

我有一個問題。

今天,我做了一個用於將數據插入MySQL數據庫的android應用程序。

當我嘗試插入String類型(例如: name )時,在記錄中顯示以下內容: “ name”

數據庫中的行 <----在數據庫中看起來像這張圖片

如何從插入的字符串中刪除

這是我的PHP腳本:

<?php
require "connect.php";

$firstHash = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUWYZX", 5)), 0, 5);
$secondHash = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRSTUWYZX", 5)), 0, 20);

$file_path_URL = "";

$id = "PRD-$firstHash-$secondHash";
$name = $_POST["name"];
$description = $_POST["description"];
$price = $_POST["price"];
$state = $_POST["state"];
$category = $_POST["category"];

$file_path = "uploads/";

$response = array();

if (isset($_FILES["upload_file"]))
{
    $target_file_name = $file_path .basename("$id.png");

    if(file_exists($target_file_name))
    {
        $success = false;
        $message = "Name already exist";
    }
    else
    {
        if (move_uploaded_file($_FILES["upload_file"]["tmp_name"], $target_file_name))
        {
            $photoPath = "$file_path_URL$id.png";
            $query = "INSERT INTO `produkty`(`ID`, `Nazwa`, `Opis`, `Cena`, `Stan`, `Zdjecie`, `Kategoria`) VALUES ('$id', '$name', '$description', $price, $state, '$photoPath', '$category')";

            $result = mysqli_query($conn, $query);

            if(!$result)
            {
                $success = false;
                $message = "Error on insert data";
            }
            else
            {
                $success = true;
                $message = "Add product successfuly";
            }
        }
    else
        {
            $success = false;
            $message = "Error while uploading";
        }

    }


}
else
{
    $success = false;
    $message = "Required Field Missing";
}

$response["success"] = $success;
$response["message"] = $message;

$json = json_encode($response);

echo ($json);
?>

負責從Android用戶獲取輸入數據的方法:

    private void getValues()
{
    Log.v(TAG, "getValues(): init");

    EditText nameET = findViewById(R.id.nameET);
    EditText descriptionET = findViewById(R.id.descriptionET);
    EditText priceET = findViewById(R.id.priceET);
    EditText categoryET = findViewById(R.id.categoryET);
    CheckBox stateCHB = findViewById(R.id.checkBox);

    String name = nameET.getText().toString();
    String description = descriptionET.getText().toString();
    Float price = Float.valueOf(priceET.getText().toString());
    String category = categoryET.getText().toString();
    boolean state;

    if (stateCHB.isChecked())
    {
        state = true;
    }
    else
    {
        state = false;
    }

    sendDataToServer(name, description, price, state, category, imagePath);

    Log.v(TAG, "getValues(): end");

}

我像String一樣將其發布到PHP。 這是個錯誤 ?

我是第一次從Android應用程序插入MySQL數據庫。 請幫我 !

我沒有立即看到報價的來源。 也許在“ sendDataToServer”內部,但是一種解決方案是替換

$name = $_POST["name"];

$name = str_replace( '"', '', $_POST["name"]);

在您的PHP代碼中,以在POST請求到達時刪除引號。

暫無
暫無

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

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