Page 1 of 1

AES_ENCRYPT issue

Posted: Wed Feb 04, 2015 6:05 pm
by cap2cap10
Hello again, members of the PHP Technorati! Again, I come to you with a distressing issue involving the insertion of data using
AES_ENCRYPT in mysql.

Here is the error:
Could not insert data into table: 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 'AES_ENCRYPT('7464', 'true'), AES_ENCRYPT('347', 'true'), AES_ENCRYPT('659', ' at line 33

Here is the code:

Code: Select all

$vkey_1 = $_POST['vkey_1'];
$site_id= rand(11111111, 99999999);
$c_data_1 = $_POST['c_data_1'];
 $c_data_2 = $_POST['c_data_2'];
 $c_data_3 = $_POST['c_data_3'];
 $c_data_4 = $_POST['c_data_4'];
 $c_data_5 = $_POST['c_data_5'];
 $c_data_6 = $_POST['c_data_6'];
 $c_data_7 = $_POST['c_data_7'];
 $c_data_8 = $_POST['c_data_8'];
 $c_data_9 = $_POST['c_data_9'];
 $c_data_10 = $_POST['c_data_10'];
 $c_data_11 = $_POST['c_data_11'];
 $c_data_12 = $_POST['c_data_12'];
 $c_data_13 = $_POST['c_data_13'];
 $c_data_14 = $_POST['c_data_14'];
 $c_data_15 = $_POST['c_data_15'];
 $c_data_16 = $_POST['c_data_16'];
 $c_data_17 = $_POST['c_data_17'];
 $result = "INSERT into clnt_tbl (site_id,
 c_data_1,
 c_data_2,
 c_data_3,
 c_data_4,
 c_data_5,
 c_data_6,
 c_data_7,
 c_data_8,
 c_data_9,
 c_data_10,
 c_data_11,
 c_data_12,
 c_data_13,
 c_data_14,
 c_data_15,
 c_data_16,
 c_data_17
 )VALUES (".$site_id.",
 AES_ENCRYPT('$c_data_1', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_2', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_3', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_4', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_5', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_6', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_7', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_8', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_9', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_10', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_11', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_12', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_13', '".$vkey_1."')
 AES_ENCRYPT('$c_data_14', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_15', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_16', '".$vkey_1."'),
 AES_ENCRYPT('$c_data_17', '".$vkey_1."'))";
 //AES_ENCRYPT('c_data_14', '".$vkey_1."'),
 mysql_select_db('mdo_db');
$retval = mysql_query( $result, $conn );
if(! $retval )
{
  die('Could not insert data into table: ' . mysql_error());
}
echo "<li><font face=Verdana size=0 color=#4EA24F> Client Form_tbl data inserted and encrypted successfully!</font></li><p>\n";


It is not adding the data to the tbl. I am using Varbinary(200) to make sure there is enough space. Please show me the
error in my logic so I can take a break and not become some Obsessive compulsive programmer descending into madness.

Thanks in advance,

Batoe

Re: AES_ENCRYPT issue

Posted: Wed Feb 04, 2015 7:41 pm
by requinix
You're missing a comma in the SQL. Visually scan up and down the lines - it should stand out.