Jump to content

jamina1

Members
  • Posts

    32
  • Joined

  • Last visited

Posts posted by jamina1

  1. Hello!

    We have a weird problem with PHP, MySQL, Phpmyadmin and some chinese characters.

     

    The page in question has a "contact" form - which emails to our sales department. We *finally* got chinese characters coming through the email by converting the page to utf8. However, now that we're storing the data in our database we've come across a problem.

     

    When I do show variables like 'c%';

    I get the following:

    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | latin1                     |
    | character_set_connection | latin1                     |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | latin1                     |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    | collation_connection     | latin1_swedish_ci          |
    | collation_database       | utf8_general_ci            |
    | collation_server         | utf8_general_ci            |
    

     

    With this setup, we put some chinese characters through PHP. They go in, and when we query through PHP they look fine.

    But in phpmyadmin they look like this: 测仪è”系(美国). Not cool.

     

    So I tried to convert all the other things to utf8 by using the SET NAMES 'utf8';

    Here's what it looks like after the SET NAMES:

     

    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    | collation_connection     | utf8_general_ci            |
    | collation_database       | utf8_general_ci            |
    | collation_server         | utf8_general_ci            |
    

     

    But it STILL looks like 测仪è”系(美国) in phpmyadmin.

    We need 本网站发送的所有电子邮件都有记录以用于商店管理 to look like chinese, not 测仪è”系(美国).

     

    How can we accomplish this?

  2. And you've used "SET NAMES" in your mysql connection from php, and defined everything else correctly w.r.t encoding/

     

    Yes, it just sort of changes what goes on with the improperly entered data.

     

    See here on this page, the 2nd bullet point: http://www.testequipmentconnection.com/products/36938

    And here on this page, where the page is UTF-8 encoded: http://70.86.88.202/~tec/products/36938

     

    This is what has happened to the database. It was created, and filled with data completely in English - much of it copy and pasted from other sources. Quite a bit of it contains HTML code.

     

    About 6 months ago, they decided it needed to be able to support chinese characters, which since it was currently in Latin encoding, it wasn't going to be able to do.

     

    We changed the charset and coallation on the database, but I don't think it converted the data.

    New data goes in as UTF-8 so it looks right. Old data is sort of a tossup with special characters.

  3. Is the database correct and the output wrong? or are both wrong?

     

    Its in plain HTML in the database. It's when it's read out that it becomes wrong.

    Say you have an   in there.

     

    In the database it says   or © or ® or whatever.

     

    When it reads out in iso-5589-1 encoding on an html page, its a big black square with a ? in it.

     

    If I change the page to UTF-8, its just a ?.

     

    We need to rectify the problems with the data in the database ( , registered symbols, tm symbols, r symbols weren't encoded properly when they were inserted... or something) so that I can make our pages uniformly UTF-8 encoding without the jibberish showing up and my boss freaking out.

     

    If I go in and edit it using UTF-8 it sorts itself out, but I just need to know if there's a way to single these entries out, or wholly convert all the rows (in a database of about 30k rows) without just stumbling across them as I browse our products.

  4. I'm not sure I understand... you have to specify the encoding of the connection, too.

     

    Here's what we have. We have a database that was entered in latin encoding that is now UTF-8 Charset, and utf collation, but the data in the fields is the same. (when we changed the charset and collation the data was not converted)

    The database connection is in utf-8, but some special characters, like non-breaking spaces, and other weird html entities show up as garbled text, diamond ???'s or just ?'s once we switch the pages they're brought up on from iso-5589-1 to utf-8.

     

    I need to know, is there a way to find these entries so they can be fixed, or is there a way to convert the data entirely?

     

    It isn't a problem if I *leave* the english pages as iso-5589-1 encoded, but that leaves my other more pertinent email problem outstanding, which the only solution I've found is to convert the english pages to utf-8..

  5. Hi guys -

     

    I have a problem with our website and various encodings. We have a chinese and an english website. We use a program called Zen-Cart for the english site and we just copied over the pertinent "info" pages and translated them into chinese instead of duplicating our entire product database.

     

    The chinese pages are in utf-8. The english pages are in iso-8859-1.

     

    Problem being whenever someone enters chinese into a form, it is processed by the zencart scripts, thus the encoding is swapped and the characters get screwed. Easy solution, convert the english page to utf-8 (which I want to do!)

     

    Problem is that then   and other characters like the R, C and TM symbols start showing up funny on the now-UTF-encoded english pages.

     

    Is there anyway to do a SELECT to find these weird entries and thus fix them BEFORE we change our page to unicode so that my boss doesn't freak out that half our pages will be messed up.

     

    I know unicode will fix all our problems, I just need to figure out how to ensure our database is COMPLETELY unicode compliant (data was entered as english/lating/iso-whatever encoding)

     

    So after all this rambling I need to know

    1) Is there a way to find the entries in the database that are non compliant with UTF-8 so we can fix them?

    2) Is there a way to convert the database and its contents (not just the coallation and charset) to utf-8? I've tried

    UPDATE $table SET $column=CONVERT(CONVERT(CONVERT($column USING latin1) USING binary) USING utf8)

    and

    ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

    to no effect.

  6. I've tried all I can, but I can't get PHP to convert a string to an integer (or pull the numbers OUT of a string) if it doesn't start with a number, which is an issue.

     

    Basically, i'm trying to pull the integers only out of various model numbers for pieces of equipment our store is selling - examples would be something like S820D or MS1798. I only need the 820 or the 1798 from these strings, but PHP doesn't want to play nice with either:

    $product_model = "S820D";
    $var = intval($product_model);
    

    or

    $var = (int) $product_model;
    

     

    Help!

  7. Hi guys-

     

    I looked around to solve a problem I'm having with PHP truncating values longer than 255 characters in a Varchar field in my database.

    I can't convert the column to TEXT because I have to run DISTINCT on a few queries, and TEXT doesn't compute with it.

     

    Is there any way to get around the PHP truncation?

  8. Hi all!

     

    I'm kinda newish to Javascript, and it's not wanting to play nice with my PHP code.

     

    I have a form set up like this:

    <input type="text" name="startdate[]" id="startdate1">
    <input type="text" name="startdate[]" id="startdate2">
    

    The fields must have the same name because I want PHP to parse them as an array.

    In javascript when I use document.getElementById('startdate1'), it always sees the name of the field, so when I try to pass a value back to it, it sends an error because it tries to assign a value to 'startdate[]'

    The fields must be named as they are.. is there a way to tell javascript to use the ID, rather than the name?  ???

  9. Ok, I changed News.php to account for your suggestions, but its still giving me an error  >:(

     

    db.php:

    <?
    require("config.php");
    class mssqlDB
    {
    	var $connection;         //The mssql database connection
    
    	/* Class constructor */
    	function mssqlDB(){
    		/* Make connection to database */
    		$this->connection = mssql_connect(DB_SERVER, DB_USER, DB_PASS);
    		mssql_select_db(DB_NAME, $this->connection);
    	}
    
    	/* Query Function */
    	function query($query){
    		return mssql_query($query, $this->connection);
    	}
    
    	/* Test Function */
    	function test() {
    		return "This is a test";
    	}
    
    };
    ?>

     

    news.php:

    <?
    include("db.php");
    class News
    {				
    	/* fetchNews - returns a list of most recent news posts and paginates $perpage, else just returns top 5 posts */
    	function fetchNews($page) {
    		$database = new mssqlDB;
    		$RowsPerPage = 10; // Rows Per Page
    		$startRows = ($page-1)*$RowsPerPage;
    		$q = "SELECT * FROM ".NEWS_POSTS." ORDER BY timestamp DESC";
    		$result = $database->query($q);
    		$numrows = mssql_num_rows($result);
    		if($numrows == 0) {
    			return "There are no news posts to display";
    		} else {
    			@mssql_data_seek($result, $startRows);
    			return $result;
    		}			
    	}
    
    	/* countNews - returns how many news posts are currently in the database */
    	function countNews() {
    		$database = new mssqlDB;
    		$q = "SELECT * FROM ".NEWS_TABLE;
    		$query = $database->query($q);
    		$rows = mssql_num_rows($query);
    		return $rows;
    	}
    
    
    };
    /* Initialize Class Object */
    $news = new News;
    ?>

     

    And it says: Cannot instantiate non-existent class: mssqldb in news.php in both functions.

  10. Then it says I can't redeclare the class.. this is being a pain. It recognizes the fact that the class has been declared once so it won't let me redeclare it, but it won't see it in the first place.

     

    What gives?

     

    Here's how its included:

     

    On index.php

    require("functions.php")

     

    and functions.php looks like this:

    <?
    session_start();
    require("config.php");
    require("db.php");
    require("news.php");
    

     

    So, why won't it see the database class?

  11. Hi, I'm somewhat new to classes. I've added on to a system that used them and thought I had them down, but when I try to create my own all I get is errors. Here's excerpts of what I have: (Config.php is just defined constants, and shouldn't be causing the issues here)

     

    db.php

    <?
    require("config.php");
    class mssqlDB
    {
    	var $connection;         //The mssql database connection
    
    	/* Class constructor */
    	function mssqlDB(){
    		/* Make connection to database */
    		$this->connection = mssql_connect(DB_SERVER, DB_USER, DB_PASS);
    		mssql_select_db(DB_NAME, $this->connection);
    	}
    
    	/* Query Function */
    	function query($query){
    		return mssql_query($query, $this->connection);
    	}
    
    };
    /* Create Database Connection */
    $database = new mssqlDB;
    ?>

     

    news.php

    <?
    class News
    {				
    	/* fetchNews - returns a list of most recent news posts and paginates $perpage, else just returns top 5 posts */
    	function fetchNews($perpage) {
    	}
    
    	/* countNews - returns how many news posts are currently in the database */
    	function countNews() {
    		global $database; // Database object
    		$q = "SELECT * FROM ".NEWS_TABLE;
    		$query = $database->query($q); // <-----Causes problems
    		$rows = mssql_num_rows($query);
    		return $rows;
    	}
    
    
    };
    /* Initialize Class Object */
    $news = new News;
    ?>

     

    I also have a file called functions.php, which will be included on every page of the site and holds basic php functions I use down the page. It require()'s both db.php and news.php at the top of the file. Yet, when I load up any page on my site that calls a function using the news class, I get this:

    Fatal error: Call to a member function on a non-object in D:\wwwroot\undergraduateStudies.ucf.edu\cpanel\includes\news.php on line 12

    Line 12 is the reference to the database class. Why aren't the classes loading properly?

     

  12. that one works, i just cant understand what is the diffrent can u explain if u dont mind in case i get the same problem in the future

    He added an exit; after the Try Again? statement. That's the only difference.

  13. The javascript has to insert data into a table structure so its complicated. The command that actually prints out the <input> field is element.innerHTML like so:

     

    	k.innerHTML = "<input name=\"starttime[]\" type=\"text\" class=\"bordered\" size=\"25\" />"
    

     

    The javascript works perfectly, its the PHP I'm having issues with. Even if I assign the javascript inserted text boxes a predetermined value with value="something" that doesn't show up in the $_POST array.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.