Using php, mysql and mcrypt together

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the_brad
Forum Newbie
Posts: 3
Joined: Sun Sep 10, 2006 5:42 pm

Using php, mysql and mcrypt together

Post by the_brad »

I'm having this problem:

Code: Select all

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 '‡ÅÜÒVSkã'4÷‹O2 zW ,u^Üê[', '\”$«5Þ{' at line 2
When I'm trying to use this statement:

Code: Select all

$entry_sql = "INSERT INTO Users (login) VALUES(' " . encrypt($_POST[Username]) . " ')";
Where the encryption function looks like:

Code: Select all

function encrypt($string)
{
	global $master_key;
	
	$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
	$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
	
	return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $master_key, $string, MCRYPT_MODE_ECB, $iv);

}//encrypt
I'm totally new to the mcrypt library and truly have no idea why I am receiving this error, but I believe it may have something to do with the encryption function returning quotation marks in the returned string.

Any help would be much appreciated.

Thanks
Last edited by the_brad on Tue Sep 12, 2006 10:54 am, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

the_brad
Forum Newbie
Posts: 3
Joined: Sun Sep 10, 2006 5:42 pm

Post by the_brad »

That worked to get the encrypted data into the db, but now when I retrieve the data and decrypt it with this function

Code: Select all

function decrypt($string)
{
	global $master_key;
	
	$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
	$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

	return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $master_key, $string, MCRYPT_MODE_ECB, $iv);
}//decrypt
It no longer works.

Thanks for the help and any additional help would be appreciated.
the_brad
Forum Newbie
Posts: 3
Joined: Sun Sep 10, 2006 5:42 pm

Post by the_brad »

any help?
Post Reply