chandldj
asked on
apostrophe issues when sending text to db
I need to send data in a textarea to a memo field in the db(access 2000). the problem is apostrophes or quotes or single quotes can easily end up in the text. I have tried the following but the apostrophe keeps causing an error. I cannot find a solution for this.
$squo = "'";
$dquo = """;
$notes = stripslashes(ereg_replace( "'",$squo, $_POST["ot her_notes" ]));
$notes = stripslashes(ereg_replace( '"',$dquo, $_POST["ot her_notes" ]));
$str_lines = "Insert into lead_lines(empID, leadID, date_, notes) VALUES(".$_POST["pick_emp" ].",".odbc _result($r s_leadid, "callID").",'".$_POST["dat e_entered" ]."','".$n otes."')";
the resulting sql statement is:
Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,'8/19/2005',' This guy seems like a real easy going dude. Might've been high when he ordered.')
The problem is in the might've, i've also tried to insert it like might\'ve -- doesn't work
Is there a way to make it literally write ' instead of placing a ' ?
Because I ran the query in access with the character code rather than the apostrophe and it worked.
Any help is appreciated
$squo = "'";
$dquo = """;
$notes = stripslashes(ereg_replace(
$notes = stripslashes(ereg_replace(
$str_lines = "Insert into lead_lines(empID, leadID, date_, notes) VALUES(".$_POST["pick_emp"
the resulting sql statement is:
Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,'8/19/2005',' This guy seems like a real easy going dude. Might've been high when he ordered.')
The problem is in the might've, i've also tried to insert it like might\'ve -- doesn't work
Is there a way to make it literally write ' instead of placing a ' ?
Because I ran the query in access with the character code rather than the apostrophe and it worked.
Any help is appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
paul is right. where u have lon texts input by user or otherwise and u r using dynamic queries like in ur example always place it witha replace command which shall replace a single apostrophe with two.
Prashant
Prashant
ASKER
If i replace the single quote with 2, will that not create 2 separate strings that access will think I am sending too many values than fields specified? Also, with the date, I actually have it sitting in a text field so it is happy to take it with surrounding single quotes.
ASKER
Actually that worked I changed it to
$squo = " ' ' ";
$notes = stripslashes(ereg_replace( "'",$squo, $_POST["ot her_notes" ]));
it got inserted
Thanks.
$squo = " ' ' ";
$notes = stripslashes(ereg_replace(
it got inserted
Thanks.
How's I not get any points. :(
dont loose the spirit paul.....
after all its just knowledge sharing. and moreover it was just a 20 points question.
cheers!!
Prashant
after all its just knowledge sharing. and moreover it was just a 20 points question.
cheers!!
Prashant
guys i dont have any problem with points being awarded to paul....
thats fine with me.
chandldj you may ask Lunchy to change it.
Prashant
thats fine with me.
chandldj you may ask Lunchy to change it.
Prashant
ASKER
I gave the points to prashant because he was the one who mentioned that I should double up the single quote to get it accepted. Paul told me that I should put pund signs around my date. Sorry guys. No disrespect intended.
That is my second comment, did you read my first?
Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,#8/19/2005#,"T