繁体   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