April 2, 201313 yr Hi,I have a problem with the form on my website here:yeparticles .com/orderThe problem is that all ' (single-quote), " (double quote) and \ (backslash) are escaped with a backslash automatically.I turned off magic_quotes in php .ini, but the problem is still there (I used phpinfo to check that magic_quotes are really off).So I used stripslashes() in the code that pass the values into the database: $articleDetails['comments'] = stripslashes($_POST['comments']); $articleDetails['articlenames'] = stripslashes($_POST['articlename']); $articleDetails['articlekeywords'] = stripslashes($_POST['articlekeyword']); The problem is that it works only for the "General Guidelines for All Articles" textarea ('comments') and not for the 2 other fields: "Subject" + "Keywords/Comments" ('articlenames' + 'articlekeywords')In order to see that, you can fill in this page an email address + subject+words for one article, then click 'continue', and then click 'edit' in the Shopping Cart.Thanks,Steve
April 2, 201313 yr I think the problem may stem from trying to apply stripslashes to arrays. You will need to loop through the articlekeyword and articlename arrays and apply stripslashes to each element in those arrays individually. Also you can always use a conditional to check for magic quotes e.g. if (get_magic_quotes_gpc() ) { $articleDetails['comments'] = stripslashes($_POST['comments']); } else { $articleDetails['comments'] = $_POST['comments']; }
April 3, 201313 yr you can try the below on your $articleDetails array <?php $articleDetails = array_map('stripslashes',$articleDetails); ?> Edited April 3, 201313 yr by webdesigner93
April 3, 201313 yr Author I think the problem may stem from trying to apply stripslashes to arrays. You will need to loop through the articlekeyword and articlename arrays and apply stripslashes to each element in those arrays individually. Also you can always use a conditional to check for magic quotes e.g. if (get_magic_quotes_gpc() ) { $articleDetails['comments'] = stripslashes($_POST['comments']); } else { $articleDetails['comments'] = $_POST['comments']; } What do you mean apply stripslashes to each element in those arrays individually?
April 3, 201313 yr Author after you populate the $articleDetails array with data try <?php $articleDetails = array_map('stripslashes',$articleDetails); ?> I'm having the same problem as when I tried to add: $articleDetails['articlenames'] = stripslashes($_POST['articlename']); $articleDetails['articlekeywords'] = stripslashes($_POST['articlekeyword']); The text in the line is replaced with 'A': Edited April 3, 201313 yr by SteveJo
April 3, 201313 yr What do you mean apply stripslashes to each element in those arrays individually? <input type="text" style="width: 300px;" class="kname" name="articlekeyword[]" id="articlekeyword1" /> The form as set up uses arrays for articlename and articlekeyword so you can't apply stripslashes to the array, you have to apply the function to each individual element in the array. Do a print_r on $_POST['articlekeyword']. webdesigner93's suggestion to use array_map is a nice solution. array_map() applies the specified function to each element in the named array.
April 3, 201313 yr Author <input type="text" style="width: 300px;" class="kname" name="articlekeyword[]" id="articlekeyword1" /> The form as set up uses arrays for articlename and articlekeyword so you can't apply stripslashes to the array, you have to apply the function to each individual element in the array. Do a print_r on $_POST['articlekeyword']. webdesigner93's suggestion to use array_map is a nice solution. array_map() applies the specified function to each element in the named array. Here is the code of the form(articlekeyword): <input type="text" style="width: 300px;" class="kname" name="articlekeyword[]" id="articlekeyword<?php echo $i + 1; ?>" /> But how can I apply the function to each individual element in the array? I tried to use array_map as webdesigner93 suggested but I got this error: Edited April 3, 201313 yr by SteveJo
April 5, 201313 yr Author OK I managed to remove the backslashes by adding: $articleDetails = stripslashes_deep($articleDetails); But I still have a problem with " (double quote). There are no backslashes, but anything after the " (double quote) is being removed. In order to see that you can type: Article number "one" in the subject field in the order page: yeparticles .com/order then click 'continue', and then click 'edit' in the Shopping Cart. I don't have any problem with ' (single-quote) and \ (backslash). Thanks!!
Create an account or sign in to comment