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 17th June 2008, 12:21 PM   #1 (permalink)
BrianChesworth
Registered User
 
Join Date: May 2008
Posts: 5
Apostrophies in text boxes creating mysql error

Hi all,

perhaps an obvious problem, I use php/mysql to insert form field data into a mysql db for content management, everything was fine using php4, then the hosting server was upgraded to php5 and this problem was born, the insert script worked fine, allowed any text inputed.
Now, when a user places text into a field which includes an apostrophy (i.e. test's) the submission results in a mysql error declaring too many (')s.
This is only happening with 'INSERT' if I use 'UPDATE/SET' then I do not have any problems, but obviously I need the 'INSERT' syntax to create new entries in the table.

A snippet of the script I am using is:

PHP Code:
<?php .....dbconnect....etc ?>

<?php 
$_POST
['Info_Box2_txt']; 
$_POST['Info_Box3_txt']; 
?>
........
<?
php $sql 
mysql_query("INSERT INTO tbl_product 
(Info_Box2_txt, Info_Box3_txt) VALUES ('$Info_Box2_txt', '$Info_Box3_txt')"
) or die(mysql_error()); 
?>
........
Any thoughts?

Do I need to separate using periods (.) or quotes (") rather than apostrophies?

Why does this problem not exist when using 'UPDATE/SET'?

Regards

Brian
BrianChesworth is offline   Reply With Quote
Old 17th June 2008, 02:01 PM   #2 (permalink)
MrBen
Munky!
 
MrBen's Avatar
 
Join Date: Sep 2003
Location: nr Woking, England
Posts: 2,585
It was probably because magic quotes was turned on (which automatically escapes special characters).

Check out example #3 at PHP: mysql_real_escape_string - Manual

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 17th June 2008, 03:06 PM   #3 (permalink)
BrianChesworth
Registered User
 
Join Date: May 2008
Posts: 5
Apostrophies creating error

Cheers Ben,

Its taken me a while to extract some sense from all that was there, but I've found a solution to the problem which works;
eg.

PHP Code:
......
<?php $who = (mysql_real_escape_string($_POST['who'])); ?>

<?php $sql mysql_query("INSERT INTO tbl_product 
(who) VALUES ('$who')"
) or die(mysql_error()); ?>
......
very simplistic, and not particularly secure, but for the moment,more than sufficient.

Many Thanks

Brian
BrianChesworth is offline   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 04:19 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