I have been given a database whose content I can't modify. Everything has been going fine until I was passing some variables in a URL through a link, and an apostrophe in one of the variables (i.e "Frank's Used Cars") is causing the variables behind it to not be passed.

This is what is currently being passed:

&price=600&miles=44000&dealer=Frank

When it should be like this:

&price=600&miles=44000&dealer=Frank's%20Used%20Cars%20&telephone=111111111

As I said the problem is with the apostrophe. I've tried changing the 'dealer' field in my database on PHP myadmin to 'utf8_swedish_ci' and also changed it to this on the MySQL connection collation from 'latin1_swedish_ci'.

I have tried using the 'mysql_real_escape_string' function as shown below, and i now have a '\' on the end of frank i.e frank\, but i still dont have the rest of the string i.e Used Cars and then the phone number.

        echo"<td>";
            echo$row->price;
        echo"</td>";
        echo"<td>";
            echo$row->miles;
        echo"</td>";
        echo"<td>";
            $deal = mysql_real_escape_string($row->dealer);
        echo"</td>";
          echo"<td>";
            echo$row->telephone;
        echo"</td>";
        echo"<td><a href='look.php?price=$row->price&miles=$row->miles&dealer=mysql_real_escape_string($deal)&telephone-$telephone>More Info</a>

Obviously if I take the apostrophe out all is fine and dandy but I can't do this. And link is wrong. Any help would be great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.