Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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