Jump to content

Proper variable syntax in a string


yaateq

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/196811-proper-variable-syntax-in-a-string/
Share on other sites

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...

 

 

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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.