Jump to content

Apostrophe problem


robertboyle

Recommended Posts

Hi,

I have the following code:

[code]$sec = "Répertoires d'objets multimédias";
mysql_query("SELECT * FROM dir WHERE sec=\"$sec\" ORDER BY st ASC",$db);  [/code]

and it returns 0 rows. When I use another $sec value, one that doesn't contain an apostrophe ('), it returns normal rows. How can I fix that?

Thanks.

Robert

ll
Link to comment
Share on other sites

[!--quoteo(post=383128:date=Jun 13 2006, 07:06 AM:name=robert-boyle)--][div class=\'quotetop\']QUOTE(robert-boyle @ Jun 13 2006, 07:06 AM) [snapback]383128[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,

I have the following code:

[code]$sec = "Répertoires d'objets multimédias";
mysql_query("SELECT * FROM dir WHERE sec=\"$sec\" ORDER BY st ASC",$db);  [/code]

and it returns 0 rows. When I use another $sec value, one that doesn't contain an apostrophe ('), it returns normal rows. How can I fix that?

Thanks.

Robert

ll
[/quote]

Try using a back slash after it '\
Link to comment
Share on other sites


You dont use database connection $db on the select query

Also silly me you dont have to backslash with the double quotes in place.


[code]

//database connection here ok.

$sec = "Répertoires d'objets multimédias";

$query="SELECT * FROM dir WHERE sec='$sec' ORDER BY st ASC";

$result=mysql_query($query);

[/code]
Link to comment
Share on other sites

[!--quoteo(post=383152:date=Jun 13 2006, 08:17 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 13 2006, 08:17 AM) [snapback]383152[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Actually you can add the link in the mysql_query function, if 2 mysql connection are made to specific which to use. If there's only one connection you can leave it empty.
[/quote]

didnt no that cheers did my code make any diffrence
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You dont use database connection $db on the select query

Also silly me you dont have to backslash with the double quotes in place.[/quote]

Yes, I do, because there's an apostrophe: if i use: '$sec', MySQL will think the query is cut at the apostrophe in "..d'objets...".

The database connection is fine, it works with other values. redarrow, where do i put the backslash?

This is the query output: SELECT * FROM dir WHERE sec="Répertoires_d'objets_multimédias" ORDER BY st ASC

It should be working, but it isn't. WHY?

Thanks.
Link to comment
Share on other sites

What a huge name lol i dont no.
$sec = 'Répertoires d'objets multimédias';




Try that echo the query and post ok.

[code]

//database connection here ok.

$sec = 'Répertoires d'objets multimédias';

$query="SELECT * FROM dir WHERE sec='$sec' ORDER BY st ASC";

$result=mysql_query($query);

[/code]

or this ok

[code]

//database connection here ok.

$sec = 'Répertoires d'\objets multimédias';

$query="SELECT * FROM dir WHERE sec='$sec' ORDER BY st ASC";

$result=mysql_query($query);

[/code]
Link to comment
Share on other sites

Always use the function [a href=\"http://www.php.net/mysql_real_escape_string\" target=\"_blank\"]mysql_real_escape_string()[/a] when dealling with strings and mysql. This function will escape single and double quotes and other characters that might cause problems with mysql. It will also work with all character encodings.

[code]<?php
$sec = "Répertoires d'objets multimédias";
$q = "SELECT * FROM dir WHERE sec='" . mysql_real_escape_string($sec). '" ORDER BY st ASC";
$rs = mysql_query($q,$db) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]

Ken
Link to comment
Share on other sites

Hi,

It doesn't seem to be working.

Again, here's what I have:

[code]
$sec = "Répertoires d'objets multimédias";
mysql_query("SELECT * FROM dir WHERE sec=\"$sec\" ORDER BY st ASC",$db);
[/code]

The corresponding "sec" in the db is "Répertoires d'objets multimédias".

Affected rows for this query=0. Works with other queries with no apostrophe.

Thanks

It's here: [a href=\"http://bluleb.com/dir/?lok\" target=\"_blank\"]http://bluleb.com/dir/?lok[/a]

Try clicking on a link with no apostrophe, it displays results.

Try clicking on a link with apostrophe: no results shown.

It's here: [a href=\"http://bluleb.com/dir/?lok\" target=\"_blank\"]http://bluleb.com/dir/?lok[/a]

Try clicking on a link with no apostrophe, it displays results.

Try clicking on a link with apostrophe: no results shown.
Link to comment
Share on other sites

[!--quoteo(post=383219:date=Jun 13 2006, 12:55 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 13 2006, 12:55 PM) [snapback]383219[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Always use the function [a href=\"http://www.php.net/mysql_real_escape_string\" target=\"_blank\"]mysql_real_escape_string()[/a] when dealling with strings and mysql. This function will escape single and double quotes and other characters that might cause problems with mysql. It will also work with all character encodings.

[code]<?php
$sec = "Répertoires d'objets multimédias";
$q = "SELECT * FROM dir WHERE sec='" . mysql_real_escape_string($sec). '" ORDER BY st ASC";
$rs = mysql_query($q,$db) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]

Ken
[/quote]
Have you done this?
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.