trehoret Posted May 19, 2006 Share Posted May 19, 2006 Hi,I have some code where i am storing some passwords in the database, as a storage facility for the users.Storing the password is fine ( aes_encrypt() ) is fine, but when i want to retrieve the password using aes_decrypt i get an error : my query:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]SELECT aes_decrypt(passx, "key")FROM `tpass` [!--colorc--][/span][!--/colorc--]Error:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( passx , "key" ) FROM `tpass` LIMIT 0, 30' at line 1 [!--colorc--][/span][!--/colorc--]Now here is the weird thing:I get this error using my php code or even launching the query directly in phpmyadmin BUT if i launch the query directly in MySQL command line or even through MySQL Query Browser under windows, this is fine, i get the password, so this sounds to me like a PHP problem.Does PHP do any kind of SQL pre-validation before sending the query to the server or something ?I am using :PHP 4.4.0MySQL 4.1.13Apache 2.0.54Thanks.Jim Quote Link to comment https://forums.phpfreaks.com/topic/9961-strange-behaviour-with-aes_decrypt/ Share on other sites More sharing options...
toplay Posted May 19, 2006 Share Posted May 19, 2006 Always post the exact PHP used so people on this forum can help you easier and quicker.Are you using the "AS" keyword? example:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] aes_decrypt(`passx`, [color=red]"key"[/color]) [color=green]AS[/color] decrypted_data [color=green]FROM[/color] [color=orange]`tpass`[/color] [!--sql2--][/div][!--sql3--]Quick PHP example:[code]$sql = 'SELECT aes_decrypt(`passx`, "key") AS decrypted_data FROM `tpass`';$result = mysql_query($sql) or die("SQL: $sql <br/>Error: " . mysql_error());while ($row = mysql_fetch_assoc($result)) echo 'Data: ', $row['decrypted_data'], '<br/>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9961-strange-behaviour-with-aes_decrypt/#findComment-37033 Share on other sites More sharing options...
trehoret Posted May 19, 2006 Author Share Posted May 19, 2006 Yes I have tried using "As" but no luck either through php. Quote Link to comment https://forums.phpfreaks.com/topic/9961-strange-behaviour-with-aes_decrypt/#findComment-37045 Share on other sites More sharing options...
toplay Posted May 19, 2006 Share Posted May 19, 2006 Well, post the EXACT code!Just by going of your sql statement, you need a space before "FROM". But the error is before that.Edit:And tell us what type of editor you're using and double check to make sure there are no hidden characters in the query that's causing the syntax problem. This has happened to a few members. Are you on Windows or Linux? Quote Link to comment https://forums.phpfreaks.com/topic/9961-strange-behaviour-with-aes_decrypt/#findComment-37047 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.