Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:30:29+00:00 2026-05-26T18:30:29+00:00

Following program i picked from the php site (http://php.net/manual/en/mysqli.real-escape-string.php) and ran on my system

  • 0

Following program i picked from the php site (http://php.net/manual/en/mysqli.real-escape-string.php) and ran on my system running wamp server.
I found that escape charecter is getting added but control is not getting inside 2nd if block

Here’s the code:

<?php
$link = mysqli_connect("localhost", "admin", "admin", "sampdb");

/* check connection */
if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
}

mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");

$city = "'s Hertogenbosch";

/* this query will fail, cause we didn't escape $city */
if (!mysqli_query($link, "INSERT into myCity (Name) VALUES ('$city')")) {
        printf("Error: %s\n", mysqli_sqlstate($link));
}

 $city = mysqli_real_escape_string($link, $city);
print $city;

/* this query with escaped $city will work */
if (mysqli_query($link, "INSERT into myCity (Name) VALUES ('$city')")) {
        printf("%d Row inserted.\n", mysqli_affected_rows($link));
}

mysqli_close($link);
?>

O/P :

Error: 42000

\’s Hertogenbosch

As per example mentioned in the link : “http://php.net/manual/en/mysqli.real-escape-string.php&#8221; the control should enter into the second if block and print number of rows inserted. which is not happening in this case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:30:30+00:00Added an answer on May 26, 2026 at 6:30 pm

    The escape character is added by the mysqli_real_escape_string function, that’s it purpose. Escaping means putting the escape character (in SQL, it’s a backslash) before control characters like the apostrophe (‘).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following program: static void Main (string[] args) { int i; uint ui; i
The following program used the implementation of atomic locks from 'Cuda By Example', but
The following program will not compile: class Program { static void Main(string[] args) {
The following program terminates correctly: import System.Random randomList = mapM (\_->getStdRandom (randomR (0, 50000::Int)))
The following program does not work as I intended. #include <string.h> #include <stdio.h> int
Why following program every time prints I'm string and not I'm object. or I'm
The following program (taken from a tutorial) prints the numbers in an array in
The following program attempts to encrypt a string and save in to a text
The following program doesn't output desired data (on VC2008 compiler) #include <stdio.h> #include <string.h>
The following program prints A:C(A,B) B:C(A,B) (as it should) public interface I { string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.