Reply to topic
PHP help
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
I know that no one can actually help me without seeing my code, but I'm just wondering if anyone else has run into this situation and, if so, what was the solution?

I wrote a script to "update" a record. When I update the record using the PHP form from my development computer - it updates to the remote MySQL db just fine. Then I used this same script to create update pages for many other pages for a Content Management site I'm developing.

When I uploaded all of the administration PHP pages to the hosting server they all work except the first script that I created. I'm not getting any error message - it just doesn't update the record, but it continues to work fine from my development computer. I'm using FCKEditor to edit the pages - but some pages are "general" pages with just one block of content (and these are the ones that are giving me the trouble), while product pages have several different blocks for features, specs, etc. (and those pages work fine - remember I used the first script to create all of these update pages.)

Any ideas of where to look for the problem?
nathacof


Joined: 24 Oct 2006
Posts: 93
Location: Bear, DE
Reply with quote
MySQL has Host based permissions.

Therefore for each host you connect from there will be a different set of permissions available to you.

Are you using one of our Shared database servers? If so this won't be a problem as we allow your user to connect from any host to access your database.

In the mysql server run the following commands and get back to us:

Code:

mysql> SHOW GRANTS FOR myuser;


This should garner us more information on your user's connection limitations.
PHP script working differently on hosting server
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
Yes, this is a shared hosting database and all of the other pages connect and update just fine both from my development server and the hosting server. It's only this one page, which ironically is the first script I wrote and based all of the other scripts on.

I'm sure there's just some small item that is present that shouldn't be. The page updates fine when I run it from my development server which is running XP Pro and XXAMP to simulate an Apache server. (It's updating to the remote MySQL server.)

It's only when I move the page to the hosting server that it no longer works - the hosting server is a shared hosting LINUX server. I don't get any error message - it just doesn't update the record. (By default I have it set to echo 'page not updated' if the update fails and 'update successful' if it updates.)

My first impression was to check for case sensitivity - but I can't seem to spot anything that is in the wrong case. I'll keep staring at it - I'm positive it's some minor thing that I have in the code that LINUX doesn't like.

I was just hoping that someone else may have run into a similar situation and could spot the problem.
Now it gets even more strange...
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
Apparently, when working from the update form on the server, some pages will update in this section and some won't.

I've looked at the records in the MySQL database to see if some records have some funny characters or something... nothing.

All records will update from my development server and from the MySQL PHP Admin.

(I can also add new records and they will update using the forms on the hosting server.)

I have 4 out of 6 records that will not update when they're on the hosting server. All using the same update form and script and coming from the same table in the database.

(I know this is going to turn out to be something really stupid.)
I found the problem... and you won't believe it.
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
Seems I cannot use the apostrophe just as an apostrophe when entering data into the database via the PHP forms on a LINUX server - I have to use the ASCII code for apostrophe. Once I changed over all of these apostropes to the ASCII code, the pages updated just fine.

Funny that this wasn't a problem when data came from my development server or within the MySQL environment. I suspect that I may come across other pages with this "issue" as I work through the rest of this site.
Macai


Joined: 15 Jun 2004
Posts: 10
Location: New York
Reply with quote
In order to use an apostrophe, you can simply replace all instants of it in the string with either \' or ''.

The reason this is necessary is so that there's a clear and objective method of parsing that's also simple and to the point.

So SELECT * FROM accounts WHERE nickname = 'Pwn'd'; becomes SELECT * FROM accounts WHERE nickname = 'Pwn\'d';.

Make sense?
Apostrophes
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
I fully understand the "why" behind it, but I'm going to need to convey that information to my client who will be using the CMS portion of this site. Within the FCKEditor window, he can select "special characters" to input an apostrophe - but I have to let him know that it's mandatory that he does that or the page won't update.

What's a bit confusing is that I built the entire CMS system on my Windows box running XAMP and created and loaded the MySQL database by connecting to it remotely and this apostrophe was not a problem. Only when I moved everything to the LINUX box did it become an issue (same database, but the PHP pages for the CMS were now loaded to the LINUX box).

Notice that I used an apostrophe in this reply and it won't pose a problem... I tried using specialchar() to fix the problem with no luck.
darnold


Joined: 17 Mar 2005
Posts: 21
Reply with quote
The easiest way to fix this will be to pass your post values through addslashes() before they get to mysql.

Code:


$name = addslashes($_POST['name']);
$description = addslashes($_POST['description ']);

$sql = "UPDATE table SET name='".$name."', description='".$description."' LIMIT 1; ";



Reference: http://us.php.net/manual/en/function.addslashes.php

Dealing with quotes is always a problem however PHP makes it easy with a variety of functions for this purpose.
Thank you
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
I'll give it a try - looks like it should work.
Thanks - works great!
mawells


Joined: 11 Jun 2004
Posts: 9
Location: NH
Reply with quote
That was the little bit of code I was missing. Many thanks.
PHP help
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic