Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying PHP code from a tutorial gives Notices on my computer

Tags:

php

I have an ecommerce site based off of this tutorial.

Now, in the cart.php page, whenever someone updates the quantity and proceeds to click the Update Cart button, they are greeted with the following notices:

Notice: Array to string conversion in /home/aquadual/public_html/fiverrproject/plaincart/library/config.php on line 51

Notice: Array to string conversion in /home/aquadual/public_html/fiverrproject/plaincart/library/config.php on line 51

Notice: Array to string conversion in /home/aquadual/public_html/fiverrproject/plaincart/library/config.php on line 51
Unknown column 'A' in 'where clause'

Here is the code in the config.php file affecting this notice:

if (!get_magic_quotes_gpc()) {
    if (isset($_POST)) {
        foreach ($_POST as $key => $value) {
            **$_POST[$key] =  trim(addslashes($value));**
        }
    }

    if (isset($_GET)) {
        foreach ($_GET as $key => $value) {
            $_GET[$key] = trim(addslashes($value));
        }
    }   
}

The actual line being line 51 in the whole config file:

$_POST[$key] =  trim(addslashes($value));
like image 318
Qcom Avatar asked Dec 06 '22 01:12

Qcom


1 Answers

You actually have two problems in this error.

The first part is that you are assuming every value in your $_POST array is a string (given your use of trim() and addslashes()). This is not necessarily the case -- a value in that array could also be an array. The notices are telling you that, three times, you are trying to treat an array as if it were a string. However, these are non-fatal notices that should not directly cause your page to crash.

The second error is the last line, which is probably unrelated to the first three error lines (though it could be related indirectly... 0_0). This error is an error in a SQL query somewhere, causing a fatal error, which causes the PHP code to stop executing. It looks like you are trying to limit a SELECT or UPDATE statement based on a column that doesn't exist in the table you are querying. You should check your SQL code to make sure it's working correctly. This is probably not near line 51.

like image 120
Ben Torell Avatar answered May 10 '23 22:05

Ben Torell