0

I have a table[info] like this

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

Now I'm using this query to show these data

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

It works fine when I am searching for Dhaka, but it is not working for Cox's Bazar. Maybe for this > '

Now what can I do? Please help!

Shushil Bohara
  • 5,556
  • 2
  • 15
  • 32
SamiulHSohan
  • 167
  • 1
  • 10

2 Answers2

1

try this

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

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

Edit

creating table and insert data

enter image description here

as you see the data ise like yours.

and If I select like mine the output is true

enter image description here

CompEng
  • 7,161
  • 16
  • 68
  • 122
0

Maybe this will help for a start:

// 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;
};
?> 

and see this post: Getting results of statement

(remeber that select * is bad practice)

Community
  • 1
  • 1
Nomistake
  • 893
  • 2
  • 17
  • 32