Java00011111
Java00011111

Reputation: 7

Having trouble with escape quotes, php

I have a for loop that runs through a set of questions with a text area next to each question. But if the question or answer has an apostrophe in it (as if someone asked "Don't" or "Can't" in the question), it doesn't get inserted into the database. I've tried strip slashes and add slashes to get rid of the problem to no avail.
This is what I've got so far.

The for loop to display to the user the question without slashes.

    for($i = 0; $i< sizeof($answered); $i++)
    {
        echo "<h3><center>" . stripslashes($question[$i]) . "</center></h3>";
        show_form($question[$i]);
    }

and the POST setup:

    if ( !empty($_POST['answer']) )
    {
        $quest = mysqli_real_escape_string ($dbc, $_POST['question']);
        $answer = mysqli_real_escape_string ($dbc, $_POST['answer']);
    }

Upvotes: 0

Views: 151

Answers (3)

Zul
Zul

Reputation: 3608

set magic_quotes_gpc = Off in your php.ini

OR

add php_flag magic_quotes_gpc Off in your .htaccess

Upvotes: 0

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

Check whether the magic_quotes_gpc is enabled in your php.ini file.
If magic_quotes_gpc is enabled, first apply stripslashes() to the data.
Using this function on data which has already been escaped will escape the data twice.

Upvotes: 0

Aaron
Aaron

Reputation: 5227

Try htmlentities($question[$i], ENT_QUOTES); to store the data, and html_entity_decode($question[$i], ENT_QUOTES); to display it.

Upvotes: -1

Related Questions