Elxis CMS Forum

Support => Technical support => Topic started by: xmanhattan on March 07, 2010, 14:55:00

Title: programming question
Post by: xmanhattan on March 07, 2010, 14:55:00
Hello all,

I have written a search program that works on my local system (wamp) with both English and Greek characters.  When I put it on the Internet through Elxis as a wrapper, the search in English works but when I give it a Greek word it does not return the output.

The program, the data, and the databases are the same, and I have compared the output of phpinfo from both my system and the Internet server showing multibyte and utf-8 enabled and with the same settings.

The script includes xhtml from beginning to end and Php embedded.

Here is most of my code but without the xhtml headers:
Code: [Select]

 ini_set('display_errors','Off');
 error_reporting(0);

 mb_internal_encoding("UTF-8");
 ini_set('auto_detect_line_endings', 1);
 date_default_timezone_set('Europe/Athens');

        test_db_connect()
            or die ("Δεν είναι δυνατή η σύνδεση με τον διακομιστή, παρακαλώ ξανά δοκιμάστε σε άλλη στιγμή.
                    <br /> Cannot connect to server, Please try again at another time.<br /> \n");
        mysql_query("SET NAMES 'UTF8'");
        mysql_query("SET CHARACTER SET 'utf8'");

        print "<form action=".$_SERVER['PHP_SELF']." method=\"post\">\n";
        print "<td>\n";
        print "<input name=\"title\" size=\"60\" maxlength=\"200\"><br />\n";
        print "</td>\n";
        print "</tr><tr>\n";
        print "<td colspan=\"2\">&nbsp;</td>\n";  // <hr>draw line
        print "</tr><tr>\n";
        print "<td colspan=\"2\" align=\"center\">\n";
        print "<input type=\"submit\" name=\"phrase\" value=\"- Search -\" />";

        // INPUT ERROR CHECKING BEGINS HERE
        // alternate through variables, check for empty, validate
       //-----------------------------------------------------------------------
        if (!get_magic_quotes_gpc()) {
            foreach ($_POST as $key => $value) {
                // Assign to $temp and trim spaces if not array
                $_POST[$value] = is_array($value) ? $value : addslashes(trim($value));
            } // end foreach
        } else {
            foreach ($_POST as $key => $value) {
                // Assign to $temp and trim spaces if not array
                $_POST[$value] = is_array($value) ? $value : trim($value);
            } // end foreach
        } // end if (!get_magic_quotes_gpc

        //This stops SQL Injection in POST vars
        foreach ($_POST as $key => $value) {
            $_POST[$key] = mysql_real_escape_string($value);
        }
       
        //This stops SQL Injection in GET vars
        foreach ($_GET as $key => $value) {
            $_GET[$key] = mysql_real_escape_string($value);
        }

        $keyword = $_POST['title'];
            if (empty($keyword)) {
                print "<br />\n";
                print "<div align='center' class='red'>";
                print "No keyword was entered to search for a book!";
                print "<br /><br />\n";
                gobackpage();
                print "</div>";
                print "<br /><br />\n";
                die;
                ?>
                    </body>
                    </html>
                <?
                die;
                }

        // regular search
        $select = "SELECT * FROM $db_name.$table_name
                    WHERE ( subject     LIKE '%$keyword%' OR
                            author         LIKE '%$keyword%' OR
                            isbn         LIKE '%$keyword%' OR
                            city         LIKE '%$keyword%' OR
                            title         LIKE '%$keyword%' OR
                            owner         LIKE '%$keyword%'
                            )";
        $result = mysql_query($select) or die($errorinfo);

        // display record
        disp_recs();

Any ideas why this could be happening?

Title: Re: programming question
Post by: xmanhattan on March 08, 2010, 11:48:08
I found the error.
When I created the database for this, I forgot to change the encoding to general utf-8.
As I checked the table encoding and found that it was correctly set to utf-8 I suddenly realized that I forgot to check the database.

Solved!
Title: Re: programming question
Post by: webgift on March 08, 2010, 13:15:36
I suddenly realized that I forgot to check the database.
Solved!

 :D ;)