Log in   Register a New Account

Accessify Forum - Discuss Website Accessibility

New to the forum?

Only an email address is required.

Register Here

Already registered? Log In

Currently Online

No registered users are online.

SQL Insert Problem

Reply with quote I have column in my database which is clientRemarks and it's defined as TEXT but I have been having errors whenever a client enters remarks such "I'm not doing this" but if a client enters "I am not doing this". It's fine. Please help. The error occurs whenever a client complete a form online on the website. coding was done with php and MySQL for the website.

Thanks
Reply with quote I think your question may be answered by this tutorial on CodeFixer - the apostrophe bug.

Codefixer wrote:
To allow an apostrophe mark to be inserted into a database, simply double-up all occurences of the apostrophe mark. SQL will see two apostrophes together and treat them as a single apostrophe and at the same time realise that this doesn't signify the end of the string.

James Coltham - Local gov web manager by day, web and accessibility blogger at lunchtime, freelancer by night. Tweets at @prettysimple.
Reply with quote Hi James,

Thanks for your reply, the example in code fixer was for asp. How do i implement with PHP? this is my first experience of coding in PHP.

Thanks

Tolani
Reply with quote Hi teelan,

A word of general advice: you should never ever put user input directly into an SQL query, or you could be subject to an SQL injection attack. There's a good Wikibook about SQL injection, and the final suggestion (parameterised statements) coupled with regular expression validation sounds like the best approach for PHP. I strongly recommend you investigate this! It should also fix your apostrophe problem.
Reply with quote Hi teelan,
If you want to insert the apostrophe mark into a database then you have to double the occurrence of apostrophe. I had tried this, It really works.
Reply with quote Try this query
INSERT INTO TABLE tablename VALUES (VALUE)
or you would not have given the specific format for your data
Reply with quote Maybe it would be good to use some OCR - but I am not sure if it is any for PHP. In Java you are using Hibernate or iBATIS and you forget about the problem.
Reply with quote you just need add slashes

Code:
"INSERT INTO TABLE tablename VALUES (".addslashes($_POST['input']).") "
Reply with quote
schoolwebdesign wrote:
you just need add slashes

Code:
"INSERT INTO TABLE tablename VALUES (".addslashes($_POST['input']).") "

thanks a lot Smile
Reply with quote Try SQL insert query

INSERT INTO TABLE tablename VALUES (VALUE)

if still have issues then please reply
Reply with quote i agree with kemon and every person "INSERT INTO TABLE TABLENAME VALUES()"

Display posts from previous:   

All times are GMT

  • Reply to topic
  • Post new topic