Copying PHP code from a tutorial gives notifications on my computer

I have an e-commerce site based on this tutorial .

Now, on the cart.php page, whenever someone updates the quantity and proceeds to clicking the Update Cart button, they will encounter the following notifications:

 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 affecting this notification:

 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 is line 51 in the entire configuration file:

 $_POST[$key] = trim(addslashes($value)); 
+4
source share
4 answers

You really have two problems in this error.

The first part is that you take every value in your $_POST array - this is a string (given the use of trim() and addslashes() ). This is not necessarily the case - the value in this array can also be an array. The notifications say that three times you try to process the array as if it were a string. However, these are non-fatal notifications that should not cause your page to crash.

The second error is the last line, which is probably not related to the first three lines of errors (although this may indirectly affect ... 0_0). This error is an error in the SQL query somewhere, which leads to a fatal error, which leads to the fact that the PHP code stops executing. It looks like you are trying to restrict a SELECT or UPDATE statement based on a column that does not exist in the table you are querying. You should check your SQL code to make sure that it works correctly. This is probably not close to line 51.

+13
source

I like the code like the following

 if (!get_magic_quotes_gpc()) { if (!empty($_GET)) { $_GET = addslashes_deep($_GET); } if (!empty($_POST)) { $_POST = addslashes_deep($_POST); } $_COOKIE = addslashes_deep($_COOKIE); $_REQUEST = addslashes_deep($_REQUEST); } function addslashes_deep($value) { if (empty($value)) { return $value; } else { return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value); } } 
+2
source

Well, first of all, you should post print_r () of your $ _POST var. Anyway, there is a case where you can have an array inside $ _POST ['whatever']:

 <input type="text" name="arr[]" value="a"> <input type="text" name="arr[]" value="b"> <input type="text" name="arr[]" value="c"> 

this will produce:

 $_POST => Array( 'arr' => Array( 0 => 'a', 1 => 'b', 2 => 'c' ) ) 

Afaik, this is the only case

+1
source

Hi, I ran into a similar problem using the same tutorial.

I found this code ...

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

posted by @Chandraveer singh from this link ... error during addslashes () function in php

and replaced it with the code found in the textbook, for example. http://www.phpwebcommerce.com/source/library/config.php

and he solved my problem. Hope this helps you and everyone else to use the same tutorial.

0
source

All Articles