General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Top 3 Statistics Assignment Help Services in Australia ☛ Personalized Fabrication Options for Your Business Requirements ☛ Driving India's Economic Growth: The Role of Strategic Government Policies ☛ Affordability in Travel: The Cheapest Modes of Transportation in India ☛ Analyzing Social Media Strategies and Online Marketing Trends ☛ Understanding Leadership: Definition and Strategic Insights ☛ Freelance Jobs: An Overview ☛ Understanding Meteorology: The Science of Weather and Climate ☛ Diving into Oceanology: Careers in Marine Science ☛ Exploring Oceanography: The Science of the Seas 
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

☛ Personalized Fabrication Options for Your Business Requirements

☛ Driving India's Economic Growth: The Role of Strategic Government Policies

☛ Affordability in Travel: The Cheapest Modes of Transportation in India

☛ Analyzing Social Media Strategies and Online Marketing Trends

☛ Understanding Leadership: Definition and Strategic Insights

☛ Freelance Jobs: An Overview

☛ Understanding Meteorology: The Science of Weather and Climate

☛ Diving into Oceanology: Careers in Marine Science

☛ Exploring Oceanography: The Science of the Seas

☛ The Intersection of Geology and Geography: An In-Depth Exploration


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 |  Privacy Policy |  Our Services |  Contact us

© 2025 SRCRAFT INIDA