PHP-MySQL problem

This is a discussion on "PHP-MySQL problem" within the PHP Forum section. This forum, and the thread "PHP-MySQL problem are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jun 13th, 2006, 06:04
Junior Member
Join Date: May 2006
Location: Lebanon
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
PHP-MySQL problem

Hi,

I have the following code:

PHP: Select all



$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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 13th, 2006, 10:14
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP-MySQL problem

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 15th, 2006, 11:46
Aug Aug is offline
New Member
Join Date: Jun 2006
Location: Vegas
Age: 25
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP-MySQL problem

The proper way to do this is to espace the '. To do so simply call addslashes.

Code: Select all
$sec = "Répertoires d'objets multimédias";
$sec = addslashes($sec);
mysql_query("SELECT * FROM dir WHERE sec=\"$sec\" ORDER BY st ASC",$db);  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 16th, 2006, 11:11
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP-MySQL problem

I think we're both wrong! A beter function would be mysql_real_escape_string(), anyone else with any better ideas?!?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 16th, 2006, 13:02
Aug Aug is offline
New Member
Join Date: Jun 2006
Location: Vegas
Age: 25
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP-MySQL problem

mysql_real_escape_string is better as it uses the mysql connection but it is not necessary unless the input is from the user. However, when using mysql_real_escape_string you have to make sure the value is not numeric.

That is easily done but using the is_numeric function like so:
Code: Select all
if(!is_numeric $variable)
{
    $variable = "'" . mysql_real_escape_string($variable) . "'";
}
But that is only necessary when the input is coming from user and you wish to protect against sql injection.

A.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
phpmysql, problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP problem in Apache/PHP/MySQL JohnI PHP Forum 6 Aug 7th, 2008 10:26
Php/Mysql Image Problem csun PHP Forum 11 Oct 27th, 2007 20:12
mySQL - PHP (problem) - XML - Flash photofx PHP Forum 3 Jul 27th, 2007 17:43
Mysql syntax problem... ktsirig Databases 1 Jan 6th, 2006 15:51
Mysql sorting problem.... mills Databases 2 Jul 26th, 2005 09:08


All times are GMT. The time now is 17:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42