[1] UnderConstruction please go to upper link and click on SIGNUP TO DRIVE (Blue cruve Button) there will be a tab open type london (Not From Drop Down) only just type london and hit enter page will redirect to

dev.appcotech.com/pwrdup/static/become-postie-vehicle.php

page (This mean post keyword matched 100% with database) than come back to previous page and again type london now this time from Dropdown menu
you will find London, United Kingdom,and hit enter. They are same city but my database have only keyword london.so page will redirect to

dev.appcotech.com/pwrdup/static/city-unavailables.php

This mean result not matched 100%

I want to match only city London, United Kingdom to my database Keyword london.
I only have letters london in my database here is my code.

require_once "connection/connection.php";
if($_POST)
{ 
   $a  = $_POST['address'] ;
   $sql = "SELECT * FROM tbl_city WHERE city_name LIKE '%$a%'"; 
   $res  = mysql_query($sql);   
   $result = mysql_fetch_array($res); 

   if($result >=1){
       header("location:become-postie-vehicle.php");
       die();   
   }else{
       header("location:city-unavailables.php");
       die();
   }

where $a = $_POST['address'] ; is input field name (Where it is use for search) so please let me know how can I match the city from my database?my database is given below

CREATE TABLE IF NOT EXISTS `tbl_city` (
`id` int(100) NOT NULL,
 `city_name` varchar(100) NOT NULL
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;


  INSERT INTO `tbl_city` (`id`, `city_name`) VALUES
  (1, 'london');

Now please help me to find out solution. Remember i have used REGEXP MATCH() ... AGAINST in $sql already.it is most challenging ever.
Anyone have Solution???

Dani AI

Generated

Short version: the dropdown value includes extra text (", United Kingdom") so your current check compares the whole string against the DB value "london" and fails. Two practical fixes: extract the city name from the place data (best), or strip everything after the first comma on the server before matching (simple fallback).

Use the Places Autocomplete place object and read address_components so you get a structured city field (look for locality and, for the UK, postal_town) instead of relying on the visible text. That is more reliable than splitting on commas and is what the official samples show. (developers.google.com)

If you can’t change the client code, normalize the posted string server-side: take the substring before the first comma, trim and lowercase it, and remove diacritics if needed. Then query the database with a parameterized statement (do not concat raw POST data). You can do this parsing in SQL (SUBSTRING_INDEX) or in PHP; both work, but parsing with the Places result is preferred. (dev.mysql.com)

Example PDO flow (minimal):

$raw = $_POST['address'] ?? '';
$city = trim(mb_strtolower(explode(',', $raw, 2)[0] ?? ''));
$city = iconv('UTF-8', 'ASCII//TRANSLIT', $city);

$pdo = new PDO($dsn, $user, $pass);
$stmt = $pdo->prepare('SELECT id FROM tbl_city WHERE LOWER(city_name) = :city');
$stmt->execute([':city' => $city]);
if ($stmt->fetch()) {
    header('Location: become-postie-vehicle.php'); exit;
}
header('Location: city-unavailables.php'); exit;

Notes and cautions: stop using ext/mysql (it was removed in PHP 7); migrate to PDO or mysqli and always use prepared statements. (php.net) Also fix the present result check — test the query result/row count rather than comparing an array to an integer. — try the structured-place approach first; ’s split/substring idea is a valid fallback if you prefer server-side or SQL-only fixes.

If you're always going to have the same format of the city with a comma followed by something, you could just write the query with a substring_index to split on the comma. If it isn't always going to be that way, then of course you wouldn't be able to do that.

SELECT * FROM tbl_city WHERE city_name LIKE SUBSTRING_INDEX('London, United Kingdom', ',', 1);

This splits the string on the first comma, and uses the value of 'London' in the search.

OR

You could split the string in PHP prior to running the query.

commented: great you have done it thanks +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.