Garethp Posted September 16, 2008 Share Posted September 16, 2008 I just built a class, thought this might be the place to share it. It compares a class to a mysql value. Here it is mysql_compare($Table, $IDColumn, $ID, $CompareCol, $Value); function mysql_compare($Table, $Columna, $ID, $Columnb, $Value) { $Error = 0; $Query = mysql_query("SELECT * FROM `$Table` WHERE `$Columna`='$ID'"); if(mysql_num_rows($Query) > 1) { $Error = 1; $Errortext = "Identifier is not unique"; } else if(mysql_num_rows($Query) == 0) { $Error = 1; $Errortext = "Row does not exist"; } else { $Show = mysql_fetch_array($Query); $Compare = $Show["$Columnb"]; if($Compare == $Value) { $Errortext = 1; } else { $Errortext = 0; } } return ($Errortext); } Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/ Share on other sites More sharing options...
Mchl Posted September 16, 2008 Share Posted September 16, 2008 "SELECT `$Columnb` FROM `$Table` WHERE `$Columna`='$ID'" would be enough, wouldn't it? Also running mysql_real_escape_string on $Columnb,$Columna,$Table and $ID wouldn't hurt. Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-642770 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 What's the difference between mysql_real_escape_string() and mysql_escape_string()? Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644554 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 Description string mysql_escape_string ( string $unescaped_string ) This function will escape the unescaped_string , so that it is safe to place it in a mysql_query(). This function is deprecated. This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting. (Underlining by me) Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644642 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 What exactly does the last paragraph mean? I get that my version is depreciated. Quick question, how do I update the PHP version on EasyPHP? Because if I can't, I need to find another way to host my own PHP server, and last time I tried I had no luck Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644714 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 It means, that mysql_real_escape_string() can only be run after mysql_connect(). It needs a mysql connection to be present, so that it could escape the string according to the charset defined by for example mysql_query(""SET NAMES 'utf8'"); Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644721 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 But can I use mysql_escape_string() to escape PHP injection, even if there is no mysql involved anywhere? Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644726 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 What kind of injection you're afraid? Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644730 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 I'm not, I just want a secure site. As secure as possible. If myqsl_escape_string escapes PHP injection, I might use a combination of the two depending on what I'm escaping it for Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644733 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 I think that other methods should be used against PHP injection. Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644739 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 Honestly, this is the only one I know. Can you tell me of some others? Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644744 Share on other sites More sharing options...
Mchl Posted September 18, 2008 Share Posted September 18, 2008 That would depend on what PHP injection you're securing against. Is it eval() or require() or something else? Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644752 Share on other sites More sharing options...
Garethp Posted September 18, 2008 Author Share Posted September 18, 2008 I'm just after general knowledge. I'm not doing a big project now but the information will come in handy later Link to comment https://forums.phpfreaks.com/topic/124473-mysql_compare/#findComment-644770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.