Jump to content

Problem with apostrophe


brenda

Recommended Posts

I have the following code to search my database (obviously some of the surrounding code is not provided) but I hope this provides enough for me to be clear about my problem) :

 

$sql="SELECT *  FROM member_details WHERE state='$state' AND location='$locn' ORDER BY Surname, Given_name";

      $result=mysqli_query($conn, $sql) or die("Error in selection -".mysqli_error($conn));

      $numrows=mysqli_num_rows($result);

      if($numrows==0)

{

echo "There are no members listed in this State/Territory/location.";

}

else

{

                while($row=mysqli_fetch_array($result))

        {

                        $surname=$row['Surname'];

                        if (strstr($surname, "'")) 

                        echo "yes";

                        else echo "no";

                }

        }

This works fine if I am searching for a surname that contains a letter such as ''a".  However when I search on the apostrophe, even though I know I have several surnames in the database which contain the apostrophe, I get a 'no' response for all of them.

 

 

Thank you.

Can anyone see what I am doing wrong here please or suggest a different approach? 

 

Link to comment
Share on other sites

I presume you are suggesting that I change the code to something like the following (apologies if I have misunderstood what you are saying):

 

$sql='SELECT *

              FROM member_details WHERE Surname LIKE "%'%"';

 

Again, this works if I use LIKE "%a%" but not when I substitue the apostrophe for 'a'. 

 

In fact I get the following error message:

 

Parse error: syntax error, unexpected T_STRING in /home/...  and this message points to my $result=... line.

 

Did I misunderstand you?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.