How to search a string in table i.e. searchstring = "Gandhi Chowk"
actual code:
if(isset($_POST['companyId'])){
$companyId = $_POST['companyId'];
}
if(isset($_POST['RouteName'])){
$routeName = '%'.$_POST['routeName'].'%';
}
if(isset($_POST['cityName'])){
$cityName = $_POST['cityName'];
}
// We Will prepare SQL Query
$STM = $dbh->prepare("SELECT routeName FROM route WHERE routeName LIKE :route");
// bind paramenters, Named paramenters alaways start with colon(:)
$STM->bindParam(':route', $routeName);
// For Executing prepared statement we will use below function
$STM->execute();
// Count no. of records
$count = $STM->rowCount();
if($count==1)
{
echo "The entered string already exist";
}
else
{
$sql = "INSERT INTO route(companyId, routeName, cityName) VALUES (:companyId, :routeName, :cityName)";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':companyId', $_POST['companyId'], PDO::PARAM_STR);
$stmt->bindParam(':routeName', $_POST['routeName'], PDO::PARAM_STR);
$stmt->bindParam(':cityName', $_POST['cityName'], PDO::PARAM_STR);
$stmt->execute();
header("location:RouteList.php?NewRouteAdded=77083368");
}