UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 25th June 2008, 11:20 AM   #1 (permalink)
urbanxtremes
Registered User
 
urbanxtremes's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 85
MySQL - PHP update issue

Hello,

I have been using this code to update my news section for quite a long time; however, since the upgrade I have noticed strange things happening.

I can only add new news, and update a few news pages... Not sure why this is, UH has looked into it, and can not see where the issue is coming from - they suggested the code.

The following code is what I have been using:

PHP Code:
<?
$ud_id
=$_POST['ud_id'];
$ud_mtitle=$_POST['ud_mtitle'];
$ud_mkey=$_POST['ud_mkey'];
$ud_mdesc=$_POST['ud_mdesc'];
$ud_header=$_POST['ud_header'];
$ud_content=$_POST['ud_content'];
$ud_oneliner=$_POST['ud_oneliner'];
$ud_cat=$_POST['ud_cat'];
$ud_img=$_POST['ud_img'];
$ud_navlink=$_POST['ud_navlink'];
$ud_nav=$_POST['ud_nav'];

$db="site_com_-_tbl_news";
$link mysql_connect("127.0.0.1","username""password");
if (! 
$link)
die(
"Couldn't connect to MySQL");

mysql_select_db($db $link)
or die(
"Couldn't open $db: ".mysql_error());

mysql_query("UPDATE tbl_Hpages  SET HpagesMTitle='$ud_mtitle' ,HpagesMKey='$ud_mkey' ,HpagesMDesc='$ud_mdesc' ,HpagesHeader='$ud_header' ,HpagesContent='$ud_content' ,HpagesOne_liner='$ud_oneliner', HpagesCat='$ud_cat' ,HpagesImg='$ud_img' ,HpagesNavLink='$ud_navlink' ,HpagesNav='$ud_nav' WHERE HpagesID='$ud_id'");
echo 
"Record Updated";
mysql_close($link);
?>

Any suggestions?
__________________
~~~~~~~~~~~~X~~~~~~~~~~~~

Who Cares?

~~~~~~~~~~~~X~~~~~~~~~~~~
urbanxtremes is offline   Reply With Quote
Old 25th June 2008, 12:04 PM   #2 (permalink)
MrBen
Munky!
 
MrBen's Avatar
 
Join Date: Sep 2003
Location: nr Woking, England
Posts: 2,582
mysql_error should be useful here - PHP: mysql_error - Manual

You don't appear to be doing any cleaning or validation on your data leaving yourself open to SQL injection.

I suspect it the error will be due to apostrophes or special characters in your input. If magic_quotes was previously set to on these would have been escaped properly. See Apostrophies in text boxes creating mysql error

Ben
__________________
The impossible I can do today, miracles take a little longer

Veterinary Practice Management System by SoftFooding
Internet Data Usage Calculator: Estimate your monthly bandwidth usage for your Internet connection.
Little Red: Nordic Style Rye Bread
MrBen is offline   Reply With Quote
Old 25th June 2008, 01:22 PM   #3 (permalink)
urbanxtremes
Registered User
 
urbanxtremes's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 85
Hello MrBen,

The code is kept behind a secure directory, so I did not think it required any validation.

I have looked through the documentation which you kindly put a link to; however, makes no sense to me. If it was to do with special characters in my input, then this would effect all post and not just a select few: or would it?

The main admin for inputing new news follows the same style of code which works fine, it is just the update that is being a bit weird?

Regards,

Mark
urbanxtremes is offline   Reply With Quote
Old 25th June 2008, 03:10 PM   #4 (permalink)
knapper
Regular Member
 
Join Date: Jun 2006
Location: Co. Durham
Posts: 98
Quote:
Originally Posted by urbanxtremes View Post

I have looked through the documentation which you kindly put a link to; however, makes no sense to me. If it was to do with special characters in my input, then this would effect all post and not just a select few: or would it?
It would be possible that not all news items contain the special charters that are causing the problem, so it could just effect some.

Quote:
Originally Posted by urbanxtremes View Post
The main admin for inputing new news follows the same style of code which works fine, it is just the update that is being a bit weird?
It might be useful if you post that code as well, just for comparison.
knapper is offline   Reply With Quote
Old 25th June 2008, 03:42 PM   #5 (permalink)
urbanxtremes
Registered User
 
urbanxtremes's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 85
Hello Knapper,

This is the code I use for adding news:

PHP Code:
<?
$HpagesMTitle
=$_POST['MTitle'];
$HpagesMKey=$_POST['MKey'];
$HpagesMDesc=$_POST['MDesc'];
$HpagesHeader=$_POST['title'];
$HpagesContent=$_POST['content'];
$HpagesOne_liner=$_POST['oneliner'];
$HpagesImg=$_POST['Img'];
$HpagesCat=$_POST['category'];
$HpagesNav=$_POST['Nav'];
$HpagesNavLink=$_POST['NavLink'];


$db="site_com_-_tbl_news";
$link mysql_connect("127.0.0.1","username""password");
if (! 
$link)
die(
"Couldn't connect to MySQL");

mysql_select_db($db $link) or die("Select Error: ".mysql_error());

$result=mysql_query("INSERT INTO tbl_Hpages (HpagesMTitle, HpagesMKey, HpagesMDesc, HpagesHeader, HpagesContent, HpagesOne_liner, HpagesImg, HpagesCat, HpagesNav, HpagesNavLink) VALUES ('$HpagesMTitle','$HpagesMKey','$HpagesMDesc','$HpagesHeader','$HpagesContent','$HpagesOne_liner','$HpagesImg','$HpagesCat','$HpagesNav','$HpagesNavLink')")or die("Insert Error: ".mysql_error());
mysql_close($link);
print 
"Record added\n";
?>
Regards,

Mark
urbanxtremes is offline   Reply With Quote
Old 25th June 2008, 04:19 PM   #6 (permalink)
urbanxtremes
Registered User
 
urbanxtremes's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 85
So, it is the "Apostrophies" that I put in the input forms that are causing the trouble with updating the MySQL DB...

What the hell do I do now???????

How do I fix this code.

I have about ten sites that use this style code...
urbanxtremes is offline   Reply With Quote
Old 25th June 2008, 04:37 PM   #7 (permalink)
TygerTyger
Lumberjack and OK
 
Join Date: Aug 2004
Posts: 817
Code:
$Hpageswhatever = mysql_real_escape_string($_POST['whatever']);
TygerTyger is offline   Reply With Quote
Old 26th June 2008, 03:14 PM   #8 (permalink)
urbanxtremes
Registered User
 
urbanxtremes's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 85
Thank you TygerTyger - that works perfectly. I owe you a big drink.
urbanxtremes is offline   Reply With Quote
Old 28th July 2008, 06:12 PM   #9 (permalink)
Wran
Registered User
 
Join Date: Jul 2008
Posts: 2
Agreed

Hi,

TygerTyger is going to be having a free night out at this rate.......

I had the same problem and yes all related to the Magic_Quotes_GPC setting being 'off' now instead of 'on' as it was previously.

First of all i'm wondering if UH meant this change? Also, could it be turned back on?
Also, woulda been nice to let us know! (Or did you? ).....

C'mon UH support, Tygers earning all the beer!.......

I had to use

$articletext = urldecode(mysql_real_escape_string($_POST['articletext']));

to get rid of all the %20 's...but it worked a treat....and i'm a basic .php user - i figured out this was because of the Magic_Quotes_GPC setting..surprised though we had to wait for Tyger to point this out to us....

.....those UH support guys are drinking too many beers me thinks

Wran.
Wran is offline   Reply With Quote
Old 29th July 2008, 08:11 AM   #10 (permalink)
Terra
Registered User
 
Terra's Avatar
 
Join Date: Oct 2005
Location: old cottage
Posts: 928
The Magic_Quotes_GPC explains a lot - we had scripts failing since switching to PHP5 & weren't aware of that issue.

I've now checked 2 sites on different servers, and yes - the old PHP4 had Magic_Quotes_GPC ON, whereas the new PHP5 has it OFF.

Would have been useful to know in advance
__________________
Underground, Overground, Wombling Free!
Terra is offline   Reply With Quote
Old 29th July 2008, 09:25 AM   #11 (permalink)
Simon
Dedicated to life!
 
Simon's Avatar
 
Join Date: Jul 2005
Location: 36°38'4.48"N - 4°42'18.52"W
Posts: 2,058
Send a message via MSN to Simon Send a message via Yahoo to Simon Send a message via Skype™ to Simon
I think we were told in advance, can't remember where, but I do remember checking all my sites to make sure they would be ok for this change.
__________________
Freelance PHP Programming
__________________
Simon is offline   Reply With Quote
Old 29th July 2008, 09:46 AM   #12 (permalink)
Terra
Registered User
 
Terra's Avatar
 
Join Date: Oct 2005
Location: old cottage
Posts: 928
mh - the only reference I found is The most requested support issues?
and that's not even an "official" thread. Don't think that can count "as we were told".
__________________
Underground, Overground, Wombling Free!
Terra is offline   Reply With Quote
Old 29th July 2008, 10:23 AM   #13 (permalink)
Simon
Dedicated to life!
 
Simon's Avatar
 
Join Date: Jul 2005
Location: 36°38'4.48"N - 4°42'18.52"W
Posts: 2,058
Send a message via MSN to Simon Send a message via Yahoo to Simon Send a message via Skype™ to Simon
I'm not going to go looking for it, but we were all told about the upgrade to PHP5 and there is a list of changes on the PHP.net website, PHP developers should be aware of this kind of config change, its been around for at least 2 years.
__________________
Freelance PHP Programming
__________________
Simon is offline   Reply With Quote
Old 29th July 2008, 06:17 PM   #14 (permalink)
Wran
Registered User
 
Join Date: Jul 2008
Posts: 2
The Penny Drops!

Aaah... so what Simon is saying is this is a change in the default configuration of .php when version 5 was released from that of version 4. Made by the developers as opposed to a config change made by UH when they installed/upgraded it.

Thats fair enough i guess....

I supposed it teaches all to write safer code in the long run as as a newbie developer the security of these things is probably my biggest headache.

Friends again UH support - if you'll have me!

Wran.
Wran is offline   Reply With Quote
Old 29th July 2008, 08:38 PM   #15 (permalink)
UH-Matt
Administrator
 
UH-Matt's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 8,065
Yes basically php5 has a lot of different (opposite) default settings in its php.ini file if you compare the stock ini from v4 to v5, you would find the thing you mention is one of those changes. Its not something WE implemented
__________________
.
Matt
UnitedHosting Staff

For official support please use our helpdesk at UnitedSupport.co.uk

UnitedHosting proudly hosting more than 20,000 sites since 1998.
UH-Matt is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 06:27 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  UnitedForums  |  SEO by vBSEO 3.0.0
Copyright © 1998-2008 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309