peuge Posted March 31, 2008 Share Posted March 31, 2008 I am using a function which checks if a username is unique in a database. I have the following: function check($table, $field, $compar_to) { $sql = "SELECT '.mysql_real_esacape_string($field).' FROM '.mysql_real_escape_string($table).' WHERE "'.mysql_real_escape_string($field).'" = "'.mysql_real_escape_string($compar_to).'""; $query = mysql_query($sql); if(mysql_num_rows($query)==0) { return TRUE; } else { return FALSE; } } The error code I get is this: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in D:\Programs\EasyPHP 2.0b1\www\DataBase\functions.php on line 12 and I call the function via this: checkUnique($tbl_name,'username', $_POST['myusername']) The above function is in an if loop and the condition is if this is true then do X. Thanks Link to comment https://forums.phpfreaks.com/topic/98856-checking-a-unique-username/ Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 You can't start a string with a double quote then end with a single quote. You query should be: <?php $sql = "SELECT `".mysql_real_esacape_string($field)."`". " FROM `".mysql_real_escape_string($table)."`". " WHERE `".mysql_real_escape_string($field)."` = '".mysql_real_escape_string($compar_to)."'"; ?> Link to comment https://forums.phpfreaks.com/topic/98856-checking-a-unique-username/#findComment-505828 Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 Also, you declare your function as 'check' but you call it as 'checkUnique' Link to comment https://forums.phpfreaks.com/topic/98856-checking-a-unique-username/#findComment-505829 Share on other sites More sharing options...
peuge Posted March 31, 2008 Author Share Posted March 31, 2008 Stupid should have seen that. Thanks! It works Link to comment https://forums.phpfreaks.com/topic/98856-checking-a-unique-username/#findComment-505834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.