yaateq Posted March 28, 2010 Share Posted March 28, 2010 Hello, I am building a query... but the variable MYKEY is not resolving... $name = 'user1'; $password = 'user1password'; define('MYKEY','897sdn9j98u98jk'); $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password','MYKEY'))"); However, when I look at the resulting adodb sql...incorrect INSERT INTO TESTAES (name,passwd) VALUES ('user1', AES_ENCRYPT('user1password','MYKEY')) This is not what I want. //If I try define('SBKEY','897sdn9j98u98jk'); $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password','".MYKEY."'))"); //pay attention to the ".MYKEY." //When I look at the resulting adodb sql...correct INSERT INTO TESTAES (name,passwd) VALUES ('user1', AES_ENCRYPT('user1password','897sdn9j98u98jk')) Is appending the variable ".MYKEY." the only way to make this work?? Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/ Share on other sites More sharing options...
zeodragonzord Posted March 28, 2010 Share Posted March 28, 2010 When using the constant, don't put quotes around it. Just use it directly. $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password',MYKEY))"); Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033162 Share on other sites More sharing options...
yaateq Posted March 28, 2010 Author Share Posted March 28, 2010 Hmm... Just tried your suggested change... $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password',MYKEY))"); The sql I got was... incorrect: INSERT INTO TESTAES (name,passwd) VALUES ('user1, AES_ENCRYPT('user1password',MYKEY)) Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033170 Share on other sites More sharing options...
mrMarcus Posted March 28, 2010 Share Posted March 28, 2010 you are still using your constant incorrectly. the following will work: $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password', '". MYKEY ."'))"); Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033181 Share on other sites More sharing options...
yaateq Posted March 28, 2010 Author Share Posted March 28, 2010 you are still using your constant incorrectly. the following will work: $myown->Execute("INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password', '". MYKEY ."'))"); In my post... I indicted this syntax as the only on that WORKS... my question was is it the only way? Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033195 Share on other sites More sharing options...
mrMarcus Posted March 28, 2010 Share Posted March 28, 2010 if it works, it's the way. i'm not sure what other way you might be referring to, so please be a little more specific. is this the only way to get a constant to work in the query? is this the only way to use AES_ENCRYPT correctly? etc., etc. Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033205 Share on other sites More sharing options...
greatstar00 Posted March 28, 2010 Share Posted March 28, 2010 try to put {} around MYKEY see if it works "INSERT INTO TESTAES (name,passwd) VALUES ('$name', AES_ENCRYPT('$password','{MYKEY}'))" Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033215 Share on other sites More sharing options...
zeodragonzord Posted March 29, 2010 Share Posted March 29, 2010 The curly braces only work for variables, not constants. You'll still need to concatenate the constant with the rest of the string as mrMarcus suggested. So yes, from what I understand, concatenating it is the way to go, as you had in your second example. Quote Link to comment https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/#findComment-1033274 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.