我有问题。
今天,我制作了一个用于将数据插入MySQL数据库的android应用程序。
当我尝试插入 String 类型(例如: name )时,在记录中显示为:“名称” 。
如何从插入的字符串中删除“
这是我的PHP脚本:
---
- name: play
hosts: localhost
tasks:
- name: Check if hugepages is disabled
shell: cat /sys/kernel/mm/transparent_hugepage/defrag
register: hugepages_status
- name: display the output
debug:
var: hugepages_status.stdout_lines
when: hugepages_status.stdout is search('never')
负责从Android用户获取输入数据的方法:
<?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);
?>
我像String一样将其发布到PHP中。这是一个错误吗?
我是第一次从Android应用程序插入MySQL数据库。 请帮帮我!
答案 0 :(得分:1)
我没有立即看到报价的来源。也许在“ sendDataToServer”内部,但是一种解决方案是替换
$name = $_POST["name"];
与
$name = str_replace( '"', '', $_POST["name"]);
在您的PHP代码中,以在POST请求到达时删除引号。