robertboyle Posted June 13, 2006 Share Posted June 13, 2006 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.Robertll Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/ Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 [!--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.Robertll[/quote]Try using a back slash after it '\ Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44888 Share on other sites More sharing options...
fooDigi Posted June 13, 2006 Share Posted June 13, 2006 i output the *sql query, and see the results from there.... Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44896 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 You dont use database connection $db on the select queryAlso 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] Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44897 Share on other sites More sharing options...
joquius Posted June 13, 2006 Share Posted June 13, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44908 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44910 Share on other sites More sharing options...
robertboyle Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You dont use database connection $db on the select queryAlso 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 ASCIt should be working, but it isn't. WHY?Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44939 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44953 Share on other sites More sharing options...
joquius Posted June 13, 2006 Share Posted June 13, 2006 [code]$sec = htmlspecialchars (addslashes ("Répertoires d'objets multimédias"));$query="SELECT * FROM dir WHERE sec='$sec' ORDER BY st ASC";$result=mysql_query($query);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44955 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2006 Share Posted June 13, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-44975 Share on other sites More sharing options...
robertboyle Posted June 13, 2006 Author Share Posted June 13, 2006 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.ThanksIt'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. Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-45000 Share on other sites More sharing options...
joquius Posted June 13, 2006 Share Posted June 13, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-45002 Share on other sites More sharing options...
robertboyle Posted June 13, 2006 Author Share Posted June 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-45003 Share on other sites More sharing options...
robertboyle Posted June 13, 2006 Author Share Posted June 13, 2006 Yes, I have, it connects successfully, no query error, but returns 0 rows. Quote Link to comment https://forums.phpfreaks.com/topic/11842-apostrophe-problem/#findComment-45019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.