Hello everyone again.
With my last post a situation was solved with me extracting database info and printing it to an Excel file.
Now I’m trying to make sure my file records [B]match[U]event title
So you enter in the name of the event title and it queries the database for records matching the title.
Take this event title for instance:
“Bringing In The New Year” @ Justin’s Restaurant & Lounge
It’s weird because I’m telling it to encode for UTF-8 and save to the database with:
[code=php]$event_title = utf8_encode($eventtitle);
But it’s still saving it to the database as ISO 8859-1 Encoding.
The query from the html form field has to have the [B]same character set[B]it’s looking for
Any suggestions?
This may help:http://www.charles-reace.com/blog/2008/10/03/utf8-in-php-and-mysql/ [/QUOTE]
[code=php]
CREATE TABLE example_table (id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, x1 varchar(30), x2 varchar(100)) [COLOR="Blue"]ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci[/COLOR]
[/code]
[code=php]
$DB="name";
$linkID = @mysql_connect("localhost", "name", "password");
mysql_select_db($DB, $linkID);
mysql_query("SET NAMES 'utf8'");
$sql="INSERT INTO example_table (x1, x2, x3, x4) VALUES('$value1','$value2','$value3','$value4')";
mysql_query($sql, $linkID);
mysql_close($linkID);
[/code]
Sounds as if something somewhere in the chain is applying htmlentities() to the inputs, maybe?[/QUOTE]
[code=php]
“
[/code]
...in the data, then that's not indicating an incorrect character encoding, but that something has transformed it into a HTML character entity string.Well, if you are actually seeing...
[code=php]
...in the data, then that's not indicating an incorrect character encoding, but that something has transformed it into a HTML character entity string.
“
[/code]
[/QUOTE]
[code=php]$eventtitle = htmlentities(sanitize($event));[/code]
[code=php]$sqlstart="SELECT * FROM user_info WHERE nameofevent='".$eventtitle."' ORDER BY id";[/code]
[CODE][I]New World Order[/I][/CODE]
, it would find New World Order with no problem and pull all of the info from that row.
htmlentities(sanitize($event));
[/quote]
I'm curious about this part:
Can we see the code that puts the content into the DB as well as what the line above is doing?[/QUOTE]
[code=php]
<?php $post = $wp_query->post; ?>
<?php
if (isset($_POST['eventfield'])){
$firstname = sanitize($_POST['firstname']);
$lastname = sanitize($_POST['lastname']);
$phonenumber = sanitize($_POST['phonenumber']);
$emailaddress = sanitize($_POST['emailaddy']);
$event_title = sanitize(single_post_title('',FALSE));
$date=date("l dS F Y h:i:s A");
$ipaddr=$_SERVER['REMOTE_ADDR'];
//moved DB connection higher
$DB="dbname";
$linkID = @mysql_connect("host info", "dbname", "password");
mysql_select_db($DB, $linkID);
$sql="INSERT INTO user_info (firstname, lastname, phonenumber, user_email, nameofevent, visit_time, ipaddr) VALUES('$firstname','$lastname','$phonenumber','$emailaddress','$event_title','$date','$ipaddr')";
mysql_query($sql, $linkID);
mysql_close($linkID);
}
?>
[/code]
[code=php]
<?php
function runCompanyData($event) {
require ('addtl_validation.php');
define(db_host, "hostinfo");
define(db_user, "userinfo");
define(db_pass, "password");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "dbname");
mysql_select_db(db_name);
$eventtitle = htmlentities(sanitize($event));
$sqlstart="SELECT * FROM user_info WHERE nameofevent='".$eventtitle."' ORDER BY id";
$export = mysql_query($sqlstart);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= strtolower(mysql_field_name($export, $i)) . "t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "t";
}
$line .= $value;
}
$data .= trim($line)."n";
}
$data = str_replace("r","",$data);
if ($data == "") {
$data = "n(0) Records Found!n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";
}
?>
[/code]
[code=php]
function sanitize($value){
mysql_real_escape_string($value);
return $value;
}
[/code]
$eventtitle = htmlentities(sanitize($event));
[/quote]
Are you sure you need to use htmlentities here?[/QUOTE]
[code=php]“[/code]
[code=php]$event[/code]
, with htmlentities($event), then it will match what's being put into the database and give me the results.Those are MS word (and similar) specific characters (slanted quotes). You should be altering those to "e; instead.[/QUOTE]
What WYSIWYG embedded editor are you using (ckeditor, telerik, etc)?[/QUOTE]
I meant what embedded editor are you using in the cms?[/QUOTE]
http://dianev.com/blog/2007/12/08/microsoft-word-making-weird-characters-in-your-blog-or-email/
http://www.velvetblues.com/web-development-blog/wordpress-problems-pasted-ms-word-content/
http://wordpress.org/support/topic/how-can-i-get-microsoft-word-text-into-my-rss-feeds
http://australiansearchengine.wordpress.com/2009/03/31/convert-microsoft-word-characters/
If I get time I'll try to pass on the MS character replacement php function I borrowed from Nogdog or Mindzai (though I can't remember which at the moment).[/QUOTE]
...
If I get time I'll try to pass on the MS character replacement php function I borrowed from Nogdog or Mindzai (though I can't remember which at the moment).[/QUOTE]
Do you mean this one? ?
http://www.charles-reace.com/blog/2008/10/15/filtering-ms-word-text/ [/QUOTE]
Do you mean this one? ?
http://www.charles-reace.com/blog/2008/10/15/filtering-ms-word-text/ [/QUOTE]
0.1.9 — BETA 5.7