General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Best Europe cities to travel with Toddlers ☛ Make Your Limousine Ride Even More Special: 10 Top Ideas ☛ Leverage SEO Services to Secure Success for Your Storage Company ☛ Telerehab physical therapy : healing at your fingertips ☛ 10 Best Activities in India for Thrills and Relaxation ☛ Wedding Limos That Redefine Luxury Transportation ☛ Flying with Family: A Guide to Kid-Friendly Travel from Calgary to Kelowna ☛ How To Protect Your Privacy Online? [Complete Guide] ☛ Help and kindness is the biggest religion ☛ Burning bamboo wood is prohibited in the scriptures, Why 
Home > Culture > Organizational Culture

Php mysql code for search text with apostrophe sign


If you are facing issue with a small problem of apostrophe sign, I will explain you, How to solve apostrophe sign issue in php mysql search string.

If you are using below mysql query

INSERT INTO `table_name` (`col1`) VALUES ('abc's site');

This is wrong way for writing mysql query. This is not valid statement. Because mysql search engine denied single quote ('), double quote ("), backslash (\) and NULL (the NULL byte) from mysql string.

Best solution for this issue is escaping characters.

For more see below details.

For escaping special characters, Add backslashes to the user define characters in a string:

For example:

<?php

$string = "Who's American President?";

echo $string . " (This string is not safe for database query.)<br>";

echo addslashes($string) . " (This string is safe for database query.)";

Result:

Who's American President? (This string is not safe for database query.)

Who\'s American President? (This string is safe for database query.)

?>

Also I will recommend you, Always use escape string function when adding user provided data into the Database.

See below query for escaping apostrophe sign

Example-1: (Insert query in Mysql)

$result = mysqli_query($conn, "INSERT INTO `table_name` (`col1`) VALUES ('".mysqli_real_escape_string($conn, $_POST['txt'])."') ") or die(mysql_error());

Example-2: (Search query in Mysql)

$getRecords = mysqli_query($conn, "SELECT * FROM `table_name` WHERE `col1` ='".mysqli_real_escape_string($conn, $searchKeywords)."'  ");

Written By: Charles Miller Published in Organizational culture


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Best Europe cities to travel with Toddlers

☛ Make Your Limousine Ride Even More Special: 10 Top Ideas

☛ Leverage SEO Services to Secure Success for Your Storage Company

☛ Telerehab physical therapy : healing at your fingertips

☛ 10 Best Activities in India for Thrills and Relaxation

☛ Wedding Limos That Redefine Luxury Transportation

☛ Flying with Family: A Guide to Kid-Friendly Travel from Calgary to Kelowna

☛ How To Protect Your Privacy Online? [Complete Guide]

☛ Help and kindness is the biggest religion

☛ Burning bamboo wood is prohibited in the scriptures, Why


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Contact us

© 2023 SRCRAFT INIDA