简体   繁体   English

使用mycrypt后,SQL查询无法正常工作

[英]SQL Query not working after using mycrypt

I am really new at PHP and I'm trying to add a value to data base using this code. 我真的是PHP新手,我正在尝试使用此代码向数据库添加值。 I tried to echo all of the tags and everything worked except it doesn't show up in my data base. 我试图回显所有标签,但所有内容都起作用了,只是它没有显示在数据库中。 I had all that working as well till I added the encryption part. 在添加加密部分之前,我也进行了所有工作。 I already found that if I used MCRYPT_RAND instead of MCRYPT_DEV_URANDOM it seemed to work better. 我已经发现,如果我使用MCRYPT_RAND而不是MCRYPT_DEV_URANDOM它似乎会更好。 Something tells me it might just be a simple error that I can't find. 有人告诉我这可能只是我找不到的简单错误。 Any tips on how to find this error or answers appreciated. 有关如何找到此错误或答案的任何提示,我们感激不尽。

<?php   
$account = "$_REQUEST[Account]";
$password = "$_REQUEST[Password]";
$pin = "$_REQUEST[Pin]";
$date = "$_REQUEST[Date]";
$username1 = "$_REQUEST[Username]";
$store1 = "$_REQUEST[Store]";
$category1 = "$_REQUEST[Category]";
$amount1 = "$_REQUEST[Amount]";
$bankaccount1 = "$_REQUEST[BankAccount]";
$notes1 = "$_REQUEST[Notes]";
$millisecond = "$_REQUEST[MilliSecond]";

    $sqlaccounts = mysql_connect("localhost", "root", "")
        or die (mysql_error());

    mysql_select_db("bumblebeesaccounts", $sqlaccounts);

    $sql = "SELECT * FROM `users` WHERE `account` = '$account'";

    $result = mysql_query($sql, $sqlaccounts);

    $verify_account = mysql_fetch_assoc($result);

    $key = $verify_account['salt'];


    $username = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $username1, MCRYPT_MODE_ECB);
    $store = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $store1, MCRYPT_MODE_ECB);
    $category = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $category1, MCRYPT_MODE_ECB);
    $amount = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $amount1, MCRYPT_MODE_ECB);
    $bankaccount = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $bankaccount1, MCRYPT_MODE_ECB);
    $notes = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $notes1, MCRYPT_MODE_ECB);



$sqlconnect = mysql_connect("localhost", "root", "")
    or die (mysql_error());

mysql_select_db("bumblebeesbudgetapp", $sqlconnect);

$sqlinsert = "INSERT INTO `bob` (`id`, `date`, `username`, `store`, `category`, `amount`, `bank account`, `notes`, `millisecond`, `receiptpicture`) 
    VALUES (NULL, '$date', '$username', '$store', '$category', '$amount', '$bankaccount', '$notes', '$millisecond', '')";

 mysql_query($sqlinsert, $sqlconnect);

echo $username;
echo mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $username, MCRYPT_MODE_ECB);

?>

Array Access 阵列存取

To get values from associative array like $_REQUEST you should change the using of qoutes from 要从$_REQUEST类的关联数组获取值,您应该更改qoutes的使用

...
$account = "$_ REQUEST[account]";
...

to

...
$account = $_REQUEST["account"];
...

Insert statement 插入语句

I think the column id is a primary key, isn't it? 我认为列ID是主键,不是吗? So it couldn't be null . 因此它不能为null If its an autoincrement column, you could leave the value: 如果其为自动增量列,则可以保留以下值:

$sqlinsert = "INSERT INTO `bob` (`date`, `username`, `store`, `category`, `amount`, `bank account`, `notes`, `millisecond`, `receiptpicture`) 
VALUES ('$date', '$username', '$store', '$category', '$amount', '$bankaccount', '$notes', '$millisecond', '')";

I got it going now. 我明白了。 The biggest change that i made is I base64 encrypted all the mcyrpt data. 我所做的最大更改是我对所有mcyrpt数据进行了base64加密。

$username = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $username1, MCRYPT_MODE_ECB));
$store = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $store1, MCRYPT_MODE_ECB));
$category = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $category1, MCRYPT_MODE_ECB));
$amount = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $amount1, MCRYPT_MODE_ECB));
$bankaccount = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $bankaccount1, MCRYPT_MODE_ECB));
$notes = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $notes1, MCRYPT_MODE_ECB));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM