需要帮助显示数据库中的数据

时间:2017-03-13 08:22:53

标签: php mysql sql phpmyadmin mariadb

我有一个像这样的表[info]

+---+-------+---------------+
|id | cost  | place         |
+---+-------+---------------+
|1  | 2000  | Dhaka         | 
|2  | 1000  | Cox's Bazar   |
+---+-------+---------------+

现在我使用此查询来显示这些数据

$a_place = $_POST['place'];
query = "SELECT * FROM info WHERE place = '$a_place'";

我在寻找达卡时工作正常,但它不适用于考克斯的巴扎尔。也许为此> '

现在我该怎么办?请帮忙!

2 个答案:

答案 0 :(得分:1)

试试这个

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

query = "SELECT * from info WHERE place = '".$a_place."'";

修改

创建表格和插入数据

enter image description here

正如您所看到的那样,数据就像您的一样。

如果我像我一样选择输出 true

enter image description here

答案 1 :(得分:0)

也许这有助于一个开始:

// prepare and bind
$a_place = $_POST['place'];
$stmt = $conn->prepare("SELECT country FROM info WHERE place = '?'");
$stmt->bind_param("s", $a_place);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows){
  $stmt->bind_result($country);
  $stmt->fetch();
  $stmt->free_result();
  echo $country;
};
?> 

并看到这篇文章: Getting results of statement

(记得选择*是不好的做法)