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
https://forums.phpfreaks.com/topic/244731-problem-with-apostrophe/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.