2

Is there any needs to change the table structure or which function, so please put the solution here. thanks in advance.

My example is as:

$find_regex = 'Δ';
$replace_regex = 'Δ';
$sql = mysql_query("INSERT INTO regex_table (find_regex, replace_regex, import_date) VALUES ('$find_regex', '$replace_regex')");

When I run the above code, it executed successfully but instead of symbol(find_regex) it insert '?'

One more thing I have already tried all the suggestion likes htmlentities, htmlspecialchar and so on provided in others questions in stackoverflow but didn't resolved.

Saty
  • 22,443
  • 7
  • 33
  • 51
KTBrothers
  • 39
  • 4

1 Answers1

0

use mysql_real_escape_string($data); //where $data is your string which contains special char refer enter link description here

Before saving to db you can encrypt your data by using htmlentities(), and while retrieving data from database you can decrpt by html_entity_decode() , See the following example may be it will help you:

    <?php error_reporting(E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$db  = 'test_001';
// Create connection
$conn = new mysqli($servername, $username, $password, $db);

$find_regex = htmlentities('Δ');
$replace_regex = htmlentities('&#916;');
 $sql = "INSERT INTO regex_table (find_regex, replace_regex ) VALUES ("."'". mysqli_real_escape_string($conn, $find_regex)."', '". mysqli_real_escape_string($conn, $replace_regex)."')";
//exit;

        $result = $conn->query($sql);

        //For retrieving from database 
        $sql = "SELECT * FROM `regex_table`";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo $row['find_regex'].'<br>'.$row['replace_regex'].'<br>';
            }
        } else {
            echo "0 results";
        }




        $conn->close();
        ?>
hvs9
  • 70
  • 6
  • Or just drop using mysql_ functions, because they are deprecated, and use PDO with prepared statements & utf-8 everything. – Valdas Sep 02 '15 at 13:34
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 02 '15 at 14:06
  • Thanks to reply but I think you haven't tried yet it. I already tried this function as well as utf-8 but nothing resolved so it will be useful to post your code. – KTBrothers Sep 02 '15 at 15:55