Jump to content


Photo

Apostrophe problem


  • Please log in to reply
13 replies to this topic

#1 robertboyle

robertboyle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 June 2006 - 07:06 AM

Hi,

I have the following code:

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

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
-- Everything is part of a plan. [a href="http://www.bluleb.com" target="_blank"]http://www.bluleb.com[/a]

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 June 2006 - 07:16 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,

I have the following code:

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

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 '\
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 fooDigi

fooDigi
  • Members
  • PipPipPip
  • Advanced Member
  • 250 posts
  • LocationDuluth, Mn

Posted 13 June 2006 - 07:37 AM

i output the *sql query, and see the results from there....
All your base are belong to us.

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 June 2006 - 07:47 AM


You dont use database connection $db on the select query

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



//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);


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 08:17 AM

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.
z..z..z..z..z..z..z..z..

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 June 2006 - 08:26 AM

[!--quoteo(post=383152:date=Jun 13 2006, 08:17 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 13 2006, 08:17 AM) View Post[/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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 robertboyle

robertboyle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 June 2006 - 10:10 AM

[!--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.
-- Everything is part of a plan. [a href="http://www.bluleb.com" target="_blank"]http://www.bluleb.com[/a]

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 June 2006 - 10:49 AM

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




Try that echo the query and post ok.


//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);


or this ok


//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);


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 10:57 AM

$sec = htmlspecialchars (addslashes ("Répertoires d'objets multimédias"));

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

$result=mysql_query($query);

z..z..z..z..z..z..z..z..

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 June 2006 - 11:55 AM

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.

<?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());
?>

Ken

#11 robertboyle

robertboyle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 June 2006 - 01:05 PM

Hi,

It doesn't seem to be working.

Again, here's what I have:

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

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.
-- Everything is part of a plan. [a href="http://www.bluleb.com" target="_blank"]http://www.bluleb.com[/a]

#12 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 01:05 PM

[!--quoteo(post=383219:date=Jun 13 2006, 12:55 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 13 2006, 12:55 PM) View Post[/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.

<?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());
?>

Ken
[/quote]
Have you done this?
z..z..z..z..z..z..z..z..

#13 robertboyle

robertboyle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 June 2006 - 01:06 PM

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.
-- Everything is part of a plan. [a href="http://www.bluleb.com" target="_blank"]http://www.bluleb.com[/a]

#14 robertboyle

robertboyle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 June 2006 - 01:47 PM

Yes, I have, it connects successfully, no query error, but returns 0 rows.
-- Everything is part of a plan. [a href="http://www.bluleb.com" target="_blank"]http://www.bluleb.com[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users