473,503 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting Data into a MS SQL Database from a PHP form

10 New Member
I am trying to store a last name that contains an apostrophe (O'Merle). It appears that PHP is adding a '\' to the last name (O\'Merle). The back slash is causing a SQL error.

The last name is entered from a PHP form and is retrieved using $_POST. Is there away to keep the apostrophe or single quote and get rid of the back slash?

lastname = [ O\'Merle ]
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'Merle'., SQL state 37000 in SQLExecDirect

Thanks.
Fred Bernstein
Apr 4 '07 #1
4 5162
cassbiz
202 New Member
I am trying to store a last name that contains an apostrophe (O'Merle). It appears that PHP is adding a '\' to the last name (O\'Merle). The back slash is causing a SQL error.

The last name is entered from a PHP form and is retrieved using $_POST. Is there away to keep the apostrophe or single quote and get rid of the back slash?

lastname = [ O\'Merle ]
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'Merle'., SQL state 37000 in SQLExecDirect

Thanks.
Fred Bernstein

You will need to use stripslashes() in order to get rid of the backslashes

[php]
echo stripslashes($row['lastname']);
[/php]
Apr 4 '07 #2
iburyak
1,017 Recognized Expert Top Contributor
I am trying to store a last name that contains an apostrophe (O'Merle). It appears that PHP is adding a '\' to the last name (O\'Merle). The back slash is causing a SQL error.

The last name is entered from a PHP form and is retrieved using $_POST. Is there away to keep the apostrophe or single quote and get rid of the back slash?

lastname = [ O\'Merle ]
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'Merle'., SQL state 37000 in SQLExecDirect

Thanks.
Fred Bernstein
If you'll double an apostrophe problem will go away. Not double quote.

[PHP]O''Merle[/PHP]
Apr 5 '07 #3
fredb
10 New Member
If you'll double an apostrophe problem will go away. Not double quote.

[PHP]O''Merle[/PHP]
The double single quote helped get the record into the SQL server database. The approach that I had to take is as follows:

$lname = $_POST['lastname'];

// Remove backslash
$lastname = preg_replace('/[\\\]/','',$lname);
// Add another apostrophe (single quote)
$lastname = preg_replace('/[\']/','\'\'',$lastname);

I appreciate your help. Take care.
Fred
Apr 5 '07 #4
Motoma
3,237 Recognized Expert Specialist
Sounds like a magic_quotes_gpc problem: this link discusses the issue, and has a very nice work around.
Apr 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3661
by: Geoff Wickens | last post by:
I am quite new to all this but am trying to create a database driven site. I have been able to use information from my sample database but I now want to be able to insert data into it. At present I...
0
2419
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
5
2176
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
0
2990
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
25
3062
by: bseakgano | last post by:
I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just...
5
2010
by: bob44 | last post by:
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and...
2
5624
by: Ravigandha | last post by:
Hello everybody, My question is how to insert special characters and symbols in Mysql5 database and how to retrieve them from database in php. Here i am inserting some data from a form,by post...
6
11745
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
18
2756
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
2
3057
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.