I'm working with a client to convert his Access database into a MySQL one. He also has a website linked to the database...here is where the problem lies:
The fields in the database have too many whitespaces. EX: Instead of having space like this:
4.0L Engine
the spacing is like this:
4.0L Engine
This causes browsers like IE and Firefox to throw an error because it looks like they are displaying the incorrect amount of whitespace.
I know one solution is to go in and manually fix the whitespacing but it has 1000's of records and it will waste too much time.
I'm using CodeIgniter for his website to select the values from the database. Is there anyway I can make CodeIgniter, IE, and Firefox display the correct number of whtiespaces or automate the process of correcting the whitespaces without manually doing them?
Thanks,
Dro Sarhadian
Edit: Here is an example of an actual string in the database:
3.2L 196 OHV ENG - 1956-65 (CAST IRON ENG)
and here is how it's shown in firefox/IE
3.2L 196 OHV ENG - 1956-65 (CAST IRON ENG)
I've never heard of an error being thrown because of white space, but you could always create a script that
pulls down the record from the database
manipulates the data through regular expressions -- looking for extra white space and replacing it with the correct white space
then updates the record in the database
If you loop through all of the records, this would only need to be done once. Then the data in the database is as you intend.
Related
I am building a web application which will run in electron with angular as a frontend framework and laravel as a backend framework. In the application it's possible to login with a smartcard (thanks to node-pcsclite), it reads the bytes on the smartcard and then I convert them.
The smartcard contains a code which is linked to the staff table in my MSSQL database. I can retrieve the code from the smartcard and I can log into the application when it uses mysql as database server.
Now when I'm trying to do the same but with mssql, I get an error which should be viewed in html mode instead of the error page itself.
(The code can be alphanumeric)
So it adds all these strange characters (probably non-existing characters), not that much of a problem right? At least, that's what I thought. So I tried to fix it by using this code inside my laravel controller:
preg_replace('/[^A-Za-z0-9\-]/', '', $string);
This didn't solve anything. Then I thought I might have a problem with the query, so I ran SQL Profiler, the problem is that (probably because of the special characters) the query is broken.
select top 1 * from [Staff] where [CodeInit] = '
go
So does anyone know how to really remove the strange characters?
If you need more information feel free to ask.
I had this problem and landed to this question when searching for a solution. I was unable to find any fix.
The string with non-printable characters retrieved from mdecrypt_generic() so I wanted a way to remove those characters. When I copy and paste the retrieved value from browser to Brackets text editor, it show these red dots.
I just pasted it to google and then it was encoded to %10. Nothing helped till now, so as a temporary solution I just used rtrim() to remove those dots.
Copy the dot in brackets and replace with "DOT_HERE".
rtrim(rtrim($pvp, "DOT_HERE"), "\0\4");
"\0\4" will remove only nulls and EOT but not that dot character(%10).
Further here is a screenshot with that red dot. You can use Brackets text editor to see this.
Note that $pvp is the decrypted text.
I am using a 3rd party "shopping cart" program (CartWeaver) that uses a MySQL database. The products in my store have primary and secondary categories, the latter of which where my issue lies.
I am using date ranges (e.g. 1930-1939, 1940-1949, etc), however when I view the ranges on the product search page, the first number sequence is displaying incorrectly. For example, the date range 1930-1939 is displaying as 3860-1930, and 1940-1949 is displaying as 3880-1949 (you can see the issue at www.silverscreencollectibles.com/searchpage.php).
I have tried multiple variables to try to get around this, all to no available. Here is what I've tried: Starting the sequence with an alpha character, starting it with a special character, putting the range in single as well as double quotes, putting a space between the sequences, replacing the dash with the alpha "to". I have also deleted and recreated the subcategories, and nothing I have tried changes the result. The entry for "2000-Present" also displays incorrectly (as 4000-Present).
I'm just a dumb user, not a programmer, so any responses that anyone is kind enough to offer will need to be "dumbed down". The application support group wants me to either send them my entire database, or allow them to directly access my site...and neither option appeals to me, from a security standpoint. I thought I would throw the issue out to the StackOverFlow community to see if anyone has seen this sort of issue before, and may be able to point me in the right direction to address the issue. Thank you so much for your time.
I have multi language characters that are being inserted into a varchar column of a MySQL MyISAM table.
One particular character, and I'm sure there are others is failing to be inserted:
�
What is this character and how can I convert this character without affecting the entire word. The server side code that can be used to manipulate these words is php.
Examples of actual words including this symbol are as follows:
portugu�s
espa�a
etc
What is the best way to insert these words correctly?
Getting charactset issues right can be a bit of a mission. Have a look at this blog post I wrote a couple of weeks ago which should cover this off. Post back here if you're still having problems.
How to Avoid Character Encoding Problems in PHP
So I have this website that has a search feature which searches a table in my mysql database. The database at the moment has 1108 rows. It contains music info such as Artist and Album. Since its possible for every character to be in an artist name or album name, I've urlencoded each of those variables before being added to the database. See below:
$artist = urlencode($_POST['artist']);
$album = urlencode($_POST['album']);
So now lets pretend that I have added a new entry to the database and it contain characters that needed to be urlencoded. The database shows it fine.
Now I want to go search.
Foreign characters worked. You can see here: http://albumarrrt.net/details.php?artist=Ai%20Otsuka clicking the album link for each one works.
But now a few problems occur.
1 - If you search for '&' the search reads the %26 as nothing. It shows %26 in the address bar, but it reads it as nothing.
Here is how it is being read:
$search = $_GET['search'];
if($search == '') {
echo "Please enter a search term :(";
}
That is the only thing done with $search before it starts getting read by the database.
2 - If you search for a single or double quotes, it does some weird stuff example:
Search for " and get No matches found
for "%5C%5C%26quot%3B" Search for '
and get No matches found for
"%5C%5C%26%23039%3B"
I don't understand why it does this, because the database only contains the code for the quote and nothing else.
Those are the only two things I have found wrong with my search. Maybe I have just been looking at it too long and can't figure it out, but it perplexes my why it doesn't read '&' as anything.
Onto my last question.
My current searching method separates each word and adds %'s around it and then uses the LIKE statement to find matches. example:
Search: A bunch of Stuff (word)
the mysql query would be like:
SELECT * FROM TABLE WHERE (album LIKE '%A%' AND album LIKE '%bunch%' AND album LIKE '%of%' AND album LIKE '%Stuff%' AND album LIKE '%%28word%29%') OR (artist LIKE '%A%' AND artist LIKE '%bunch%' AND artist LIKE '%of%' AND artist LIKE '%Stuff%' AND artist LIKE '%%28word%29%')
Obviously this is putting a lot of strain on the server, and I know using LIKE statements for such large database searching is a bad idea, so what would be an alternate way of searching FULL TEXT or some other method?
Sorry for the overwhelming amount of questions, But they all sorta go hand-in-hand with each other.
edit:
Ok I've fixed my database up, but still have a few questions.
Someone suggested to convert my text from utf8 to plain utf, how would I do this?
and I am still getting the problem with the & sign.
for example:
if you search for & on google it works, however on my site, my POST result for the search query reveals nothing when searching for &.
First: don't urlencode data in the database. Urlencode data after you fetch it, as you output to HTML.
Second: do use query parameters when you use user-supplied values in SQL queries. Then you don't have to worry about quotes in the form data causing syntax errors or SQL injection risks.
Third: don't use the LIKE '%pattern%' hack; instead use a real fulltext search solution instead (either FULLTEXT or Lucene/Solr or Sphinx Search). It'll have performance hundreds or thousands of times better than using ad-hoc text searching (depending on your volume of data).
See the presentation I did for MySQL University: Practical Full Text Search in MySQL.
I don't see why you need to urlencode, I would simply use mysql_real_escape_string.
'&' is a separator in a url so it won't be passed to your script unless you urlencode it first
Another problem with urlencode is the large number of extra characters. mySQL may silently truncate the artist or title if you haven't allowed for enough characters.
DC
are you sure you don't want to be decoding the things coming from your URL's (and POSTS) before placing them in the database? If I were storing various strings, I would want to decode them to plain UTF or something and store them that way. Then I would re-encode them to display them. This might solve your search problem in and of itself.
Second, to speed up strings search access, you could create a strings table with all of your strings tokenized, and linked back to the strings that contain them. Then instead of doing a "like %$1%" you can say where $1 = stringTable.String and join against that ID. By no means count this as the optimal solution as I haven't done those performance tunes myself, it's just a suggestion.
I have a php data migration script that serializes an array of text. Somehow, and this is not in my codebase, but the script is inserting \\\\\\\r\\\\\\\n into the string. Here is an example of what the output is like:
Product Line: [56313] LEGO Batman Screenshot\\\\\\\\r\\\\\\\\n[5
6384] LEGO Batman Screenshot[56446] LEGO Batman Screenshot[56460] LEGO Batman: T
There are no line breaks in between the different products (as you can see, there are two products being shown there - that's two iterations). When the second product gets appended to the first, the \\\\\\r\\\\\\n gets prepended. This question is fairly difficult to explain, and I don't really think that any code will help explain it. What is this and how do I get rid of it? I'm on a windows platform.
You can call trim(), http://us.php.net/trim
Hard to tell what's going on without the code, but I would search the code for \r and \n and try and find out where this is being inserted.
There are various ways to trim that string back to normal, but I suggest you search for the cause of why this happens.
The many backslashes look like the result of a (multiply) botched addslashes() operation, or a string being mangled by magic_quotes_gpc. The data definitely started with a line break somewhere along the line - if you got the data from a text file, presumably from there. These are two separate issues, even if you manage to remove the newlines, the slashes issue remains.
You would have to show us more code, or examine it using test output or a debugger.