Categories
JavaScript jquery

jquery pngFix fixed

I tried to use the pngFix from this website: http://jquery.andreaseberhard.de/pngFix/. But it didn’t work and i received an javascript error in IE6.

After several minutes of debugging and tries i found out that the error is generated by old syntax in selecting elements. It used

jQuery(this).find("img[@src$=.png]").each(...);

instead of

jQuery(this).find("img[src$=.png]").each(...);

So the fix is: Remove the “@” character form the selector string.

The same thing for the “pack” version except that the replaced string is:

[@m$=.M]

and the replacement string is:

[m$=.M]

.

Categories
PHP

Php script redirects even when output started before calling header() function

This happens because of output_buffering is on.

In order to turn off output buffering modify php.ini if you have access and set:

output_buffering = Off

or add in the local directory a .htaccess file containing this line:

php_value output_buffering Off   # or 0 
Categories
Outlook 2003

Microsoft Outlook 2003 – Downloading Same Email Twice

Most of the emails I was receiving through Microsoft Outlook 2003 I was getting duplicates. The weird thing was that not every email was duplicated and many times I believed that I had fixed the problem (doing various changes in my outlook settings) but I discovered later when automatic checking occurred that I was wrong.

The problem: I discovered that I have each rule duplicated and that’s why Outlook 2003 was downloading the same email twice.

The fix: I removed the duplicated rules.

Categories
MySQL mysqldump PHP

mysqldump – with exec() function from php outputs empty file

This error occurs on any operating system (windows, linux). The problem is that instead of getting a sql file with the database data you get a empty (0 kb.) file.

So we have the following code:

$command = "mysqldump --opt --skip-extended-insert --complete-insert -h ".$DB_HOST." -u ".$DB_USER." -p ".$DB_PASS." ".$DB_NAME." > backup.sql";

exec($command, $ret_arr, $ret_code);
echo "ret_arr: <br />";
print_r($ret_arr);

and we get an empty file and no output.

So we will fix this error in a few steps:

1. First we need to make sure that we have access to mysqldump command. For Linux machines this command is accessible from anywhere if not you will have to find the place where mysqldump file is (usually the bin folder of mysql).

In order to do this we have to get some output from our command so we will strip all the options from the command and we will remain with this:

$command = "mysqldump"; // mysqldump.exe on Windows

So execute the php script. It’s ok if you get output like this:

Array
(
    [0] => Usage: mysqldump [OPTIONS] database [tables]
    [1] => OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
    [2] => OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
    [3] => For more options, use mysqldump --help
)

If you don’t see something like that then you must check to see the path to the mysqldump command.

If you are in windows make sure you append the full path to the command. If you have a folder like I have C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysqldump.exe with spaces in it you must make sure that you enclose the command between quotes like this:

$command = "\"C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysqldump.exe\" --opt --skip-extended-insert --complete-insert -h ".$DB_HOST." -u ".$DB_USER." -p ".$DB_PASS." ".$DB_NAME." > backup.sql";

If append the right path to the command and you still cannot get the output then this article can’t help.

2. Make sure you have the rights to create the sql file. This step is mostly for Linux machines where it is very possible that you may try to create a file from php in a folder where you don’t have writing rights.

So to test this after the previous step is done you can do the following: append to the previous command extra options so that the output is not returned but instead written in a file. So we have the previous command:

In Windows:

$command = "\"C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysqldump.exe\" > backup.sql";

In Linux:

$command = "mysqldump > backup.sql";

After running the file “backup.sql” should  be created.

3.  You must now correct your statement. This means that we must use the long versions of the options like this:

Windows:

$command = "\"C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\mysqldump.exe\" --opt --skip-extended-insert --complete-insert --host=".$DB_HOST." --user=".$DB_USER." --password=".$DB_PASS." ".$DB_NAME." > backup.sql";

Linux:

$command = "mysqldump --opt --skip-extended-insert --complete-insert --host=".$DB_HOST." --user=".$DB_USER." --password=".$DB_PASS." ".$DB_NAME." > backup.sql";

The fix: The options for mysqldump when called from php must be in the longer version. Instead of –u use –user, instead of –p use –password and so on.

Categories
ActionScript Flex

1144: Interface method set data in namespace is implemented with an incompatible signature in class .

Full error message: 1144: Interface method set data in namespace is implemented with an incompatible signature in class.

<package:class><mypackage:myclass></mypackage:myclass></package:class>

This error appears in Flex Builder / Eclipse on the Problems Tab.This error refers to the fact that an extended class named <package.class> with an over ridable function has a correspondent override in <mypackage:myclass> that doesn’t match the overrided function. To be more specific i’ll give you an example:
Let’s say we want to create a custom data grid header renderer and in order to do this we will create a class VerticalHeaderRenderer that will extend DataGridItemRenderer. In the class VerticalHeaderRenderer we will override the setter function for the data property like this:

override public function set data(value:Object):void{
local_var = value.toString();
}

This is the correct version and it will not give the error mentioned in the title but if we have a function that has a parameter of a different type then Object or a different return type we will receive the error.

Basically this error tells us that we are trying to override a function with different parameters or different return value type. So to escape this error you must ensure that the override is made correctly.

Hope this helps.

Good luck.

Categories
How to MySQL PHP Tutorial

How to use specific language characters with PHP and MySQL (example: Romanian)

Problem: Using specific characters from European languages like Romanian, Bulgarian, Czech and so on (usually the ones without support in ISO 8859-1) rises errors when displaying the content in browsers turning special characters in unrecognizable ones.

My fix for this problem is using UTF-8 character set encoding for every page of the website and the MySQL tables that contain the fields you are using. Also all the html encodings from PHP use the UTF-8 character set encoding (this is not mandatory).

If you already have the database, but with the default character set (latin1) and collation (latin1_swedish_ci) for the tables with text fields (of type CHAR, VARCHAR, TEXT etc) in which you need to have special characters, you should change the character set of each of those tables like this:

ALTER TABLE my_table CONVERT TO CHARACTER SET utf8;

If you don’t have the database then you should create it and when you create a table that you need to use with specific language characters, you should specify the character set for that table:

CREATE TABLE `my_table` (
`idmy_table` tinyint(3) unsigned NOT NULL auto_increment,
`my_field` varchar(255) NOT NULL default '',
PRIMARY KEY  (`idmy_table`)
) CHARSET=utf8;

The most important thing is that in PHP, after opening a database connection, before executing any query to the database, you should ensure that this code is executed

mysql_query("SET NAMES utf8", $my_conn);

This tells the server what character set the client is using for sending SQL statements and the character set the server should use to return the results to the client.

A simple example:

<?php
$my_conn = @mysql_connect("localhost", "user", "pass")
or die("There was a problem connecting to MySQL. Please try again later.");
if(!@mysql_select_db("test", $my_conn))
{
die ("There was a problem connecting to the database. Please try again later.");
}
mysql_query("SET NAMES utf8", $my_conn);
if(!empty($_GET['mystr']))
{
// insert the string into the database
$str = htmlspecialchars($_GET['mystr'], ENT_QUOTES, "UTF-8");
$query = "INSERT INTO my_table_t (my_field) VALUES('".$str."')";
$result = mysql_query($query, $my_conn);
if($result)
{
// save the id of the table row inserted
$last_insert_id = mysql_insert_id($my_conn);
// get the last inserted value
$query = "SELECT my_field FROM my_table_t WHERE idmy_table = '".$last_insert_id."'";
$result = mysql_query($query, $my_conn);
if($result && $row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$db_string = $row['my_field'] ;
}
}
}
elseif(!empty($_GET['searchstr']))
{
$str = htmlspecialchars($_GET['searchstr'], ENT_QUOTES, "UTF-8");
$query = "SELECT * FROM my_table_t WHERE my_field LIKE '%".$str."%'";
$result = mysql_query($query, $my_conn);
if($result)
{
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$search_results[$row['idmy_table']] = $row['my_field'];
}
}
}
mysql_close($my_conn);
?>
<html>
<head>
<title>Page title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?php
if(!empty($db_string))
{
echo "<strong>Inserted string</strong>: $db_string<br />";
}
?>
<form method="get" action="">
String to insert into the database <input type="text" name="mystr"/>
<input type="submit" value="GO"/>
</form>
<?php
if(!empty($search_results))
{
echo "<strong>Search results</strong>:<br />";
foreach($search_results as $id => $value)
{
echo $value."<br />";
}
}
?>
<form method="get" action="">
Search query <input type="text" name="searchstr"/>
<input type="submit" value="GO"/>
</form>
</body>
</html>

Tip: The search in Romanian language over the database (tested with MySQL LIKE operator) works like a charm when searching words that have special characters or not.

For example: In Romanian language the word “peasant” is written as “ţăran” and someone who searches it gets the same result for the search terms “taran” or “ţăran” or “ţaran” or “tărân” and so on – so this is the real magic.

UPDATE: You may also need to add a header to the php script if you use ob_start or similar php functions like this:

header("Content-type: text/html; charset=UTF-8");

this usually fixes the encoding selection in Internet Explorer for this case.

Categories
C++ Visual Studio

warning C4244: ‘argument’ : conversion from ‘double’ to ‘int’, possible loss of data

Full error message: warning C4244: ‘argument’ : conversion from ‘double’ to ‘int’, possible loss of data

Error occured on Visual Studio 2003 when compiling a C++ project.

The warning occurred because i was calling the abs function and i did not have included yet the math.h file. The reason that this warning appeared was due to the abs function that was already loaded with other libraries (stdlib.h) and it had only one defined as int abs(int) but I needed the double abs(double) overload. This way the compiler needed to let me know about the implicit cast from double to int.

Example:

double y = 1.2454;
double x = abs((double)y);

Fix:

#include <math.h>

The fix in my case is the following code added to the header of the file #include <math.h>

Categories
C++ Visual Studio

error C2724: ‘ClassName::FunctionName’ : ‘static’ should not be used on member functions defined at file scope

Full error message: error C2724: ‘ClassName::FunctionName’ : ‘static’ should not be used on member functions defined at file scope

Error occurred in Visual Studio 2003 while declaring a static function.

Header file:

class MyClass {
public:
static void FunctionName();
};

Source file:

static void MyClass::FunctionName() {
return 0;
}

The error occurs because i used the ‘static’ modifier in the source file as well as the header file.

The fix is: Remove the ‘static’ modifier from the source file

So the code in the source file will become:

void MyClass::FunctionName() {
return 0;
}
Categories
C++ Visual Studio

error LNK2001: unresolved external symbol private: static …

Full error message: error LNK2001: unresolved external symbol “private: static <type> * <Class>::<memberVariable>” (?<memberVariable>@<C@@0PADA)

Error occured on Visual Studio 2003 when compiling a C++ project.

The error occurred because memberVariable was a static variable and it wasn’t initialized.

Example:

class A {
static char * filename;
static void F(void);
} ;

Fix:

char * A::filename = NULL;

The fix in my case is the following code added to the implementation of the <Class>:
<type> <Class>::<memberVariable> = <initValue>;

Categories
Apache Web Server XML XSLT

An XSLT stylesheet does not have an XML mimetype:

Full error message: Error loading stylesheet: An XSLT stylesheet does not have an XML mimetype:

Error occured on Firefox 2.0 when working with XML, XSLT.

xml file:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="product-list.xslt"?>
<f>PRODUCT DETAILS</f>

xslt file

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>aaa</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="alert('x');">
<value-of select="f"/>
</body>
</html>
</template>
</stylesheet>

The error occurs because the web server (in my case Apache) had this entry in the mime.types file:

text/xml            xml xsl

The fix in my case is:
Change extenstion from xslt to xls on the stylesheet file or add xslt to the text/xml entry in mime.types file in Apache.