General |  Social Media |  Miscellaneous
Login
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Save Trees to Save Your Children Life ☛ Importance of practice: A story of Gurukul ☛ Cowards never remember a favor and the brave never forget a favor ☛ The true story: One and Half Ticket ☛ ghhjhjh ☛ Don't mess with health, let's know some important things related to health ☛ How was Shani Dev born and how was his vision crooked? ☛ Story of creation of man, hunger and thirst? ☛ Why is it advised to eat garlic on an empty stomach? ☛ Indian Culture: Wisdom of sages 
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

☛ Save Trees to Save Your Children Life

☛ Importance of practice: A story of Gurukul

☛ Cowards never remember a favor and the brave never forget a favor

☛ The true story: One and Half Ticket

☛ Don't mess with health, let's know some important things related to health

☛ How was Shani Dev born and how was his vision crooked?

☛ Story of creation of man, hunger and thirst?

☛ Why is it advised to eat garlic on an empty stomach?

☛ Indian Culture: Wisdom of sages

☛ Untold Story: Last debt pyre wood


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