Closed Thread Icon

Preserved Topic: mySQL... huh? Pages that link to <a href="https://ozoneasylum.com/backlink?for=18351" title="Pages that link to Preserved Topic: mySQL... huh?" rel="nofollow" >Preserved Topic: mySQL... huh?\

 
Author Thread
Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 07-10-2001 21:00

I came accross an odd problem recently:

Add/Editing data in a database that contained the ' character would throw errors when I was using it on a *nix server. However, I'm using FoxServe on my windows PC and this didn't cause errors at all.

I'm using PHP so I used this to fix it:

code:
$string = ereg_replace ("\'", "\\'", $string);



Edit: The problem with the above fix it that my code will then generate errors when I'm testing it on my Windows PC!!! Grrr.. Anyone know of a possible fix for this??

It took me ~ages~ to find this problem! I was wondering is there are any other characters that could cause the same problem??

everybody needs a swamp bear

[This message has been edited by Dracusis (edited 07-10-2001).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-10-2001 21:15

AddSlashes() is your friend...

BTW What errors did you get under Windows?



[This message has been edited by mr.maX (edited 07-10-2001).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-10-2001 21:24

I had a similar problem with slashes getting added automatically on Windows. For that I needed to add stripslashes in the code to keep slashes from getting added everytime I updated something.




Walking the Earth like Kane

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-10-2001 21:57

mysql_escape_string() is also your friend.

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 07-10-2001 23:56

Ok. Everything worked fine in Windows without touching anything. I wrote and tested the script on windows.

I then upload it to my *nix account and the mysql_query() failed. using INSERT & UPDATE...

But this only happend the second time I tried to add something to the database, so I went back and typed in inputs of special characters untill I singled it out to being the ' character.

I then added the reg_replace to escape it and it worked fine. Then I did the same to the script on my PC, but when I ran it again (back on windows this time) I got the same error as I did initaly running it on *nix.

I'm assuming that windows was automaticaly escaping the ' characters and *nix wasnt. Then when I fixed the problem windows was still auto excaping the ' which meant \' already exixted so is added another \ with unescaped the ' and added a literal \

So the final output for any ' characters in windows would have been \\' which would be a literal \ and a special ' .

Grrrrr. Stupid Windows!

I'll try AddSlashes() and see if it causes the same problem.

mysql_escape_string().. I'll try that too.

stripslashes().. I'll look into that too

God dam, there are sooooooo many inbult functions in PHP isn't not funny. And I thought using JS and the DOM was complex...

Actualy, I've decided to try and write a PHP news poster/guest book that does not use a Database. One that can also be edited rather easialy. I don't think I could have chosen a better learning exercise, learning how to take a plain text file and split it up into a multi-dimensional array is quite a task for a newbie programmer like me. Not to mention flattening the array back out into a string with the correct seperators so it can be written back to the file. It's been fun though.

Anyway, thanks for your help Guys.

everybody needs a swamp bear

[This message has been edited by Dracusis (edited 07-10-2001).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-11-2001 00:04

It's escaping special characters automatically on you computer, because you have enabled "Magic quotes" in php.ini file.

BTW PHP currently has 2026 built-in functions (but not all of them are available, because that depends on platform and how PHP is compiled).

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-11-2001 01:04

file(), implode() and explode


Walking the Earth like Kane

[This message has been edited by bitdamaged (edited 07-11-2001).]

[This message has been edited by bitdamaged (edited 07-11-2001).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 07-11-2001 06:08

mr.maX: Shit hay, that many inbuilt functions... Oh, and I just used the standard FoxServe install, didn't touch nothing cause I didn't want to break nothin (If it ain't broke don't fix it). I don't have any experience running server software of any kind on any system either so.... But I'll devote some time to reading up on the PHP config section of the manual.


bitdamaged: Yeah, I looked at those functions...

However, I managed to do eyerything I needed with split() fopen() and foreach loops.

First I'd fopen() the file into a $string, then split() it into an $array. Then I'd use a foreach loop on the $array with another split() to construct the multi-dimensional array (at least that what I think an array inside an array is called). This also keeps things as dyanamic as possible. The fopen()'nd file ends up in an array like this:

$array[0][0] - Post 0 Date
$array[0][1] - Post 0 Subject
$array[0][2] - Post 0 Content
$array[0][3] - Post 0 Posted By
$array[1][0] - Post 1 Date
$array[1][1] - Post 1 Subject
$array[1][2] - Post 1 Content
$array[1][3] - Post 1 Posted By

and so on and so on.

This only works because I've used simple generic seperators in the text file like:

[+++++post+break+++++]

and

[-----sub-break-----]

No numbres and No id's. But I don't really need them cause I can get that information once the array has been constructed. I also don't need to specify how many different sub sections I want in each entry either, so more can be added or removed at any time, as long as their's the same ammount in each entry and I can get around this but simply adding dummy sections (multiple [--sub-break--]'s with no data inbetween them).

When I want to print it back out I just use foreach with another nested foreach inside that. It all works quite well IMO. But you guys(girls) probably do this kind of stuff in your sleep but it's cool to me..... anyways again, thanks for your help.

Drac.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-11-2001 08:08

No worries

When it comes to code there are a million and one ways to skin a cat

I was just throwing things out


Walking the Earth like Kane

« BackwardsOnwards »

Show Forum Drop Down Menu