jpratt Posted August 24, 2007 Share Posted August 24, 2007 I have quite a few field where the user may type in a' or a ". how do I format the string so it inputs it into the database appropriately? Thanks. Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/ Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 <?php $str = "Is your name O'reilly?"; // Outputs: Is your name O\'reilly? echo addslashes($str); ?> also try http://www.php.net/manual/en/function.mysql-real-escape-string.php Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332649 Share on other sites More sharing options...
pocobueno1388 Posted August 24, 2007 Share Posted August 24, 2007 Definitely go with the mysql_real_escape_string() function, that is what is was made to do. Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332653 Share on other sites More sharing options...
jpratt Posted August 24, 2007 Author Share Posted August 24, 2007 $comment = $_POST['comment']; $sql = "INSERT INTO medjournal (comment) VALUES ('$comment')"; Here is a sample. I cannot use mysql_real_escape_string as i am using a sqlite db using pdo. Can anyone give me an example using this bit of code? Thanks. Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332655 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 $comment = addslashes($_POST['comment']); $sql = "INSERT INTO medjournal (comment) VALUES ('$comment')"; Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332656 Share on other sites More sharing options...
jpratt Posted August 24, 2007 Author Share Posted August 24, 2007 I tried addslashes, but it still gives an error when using ' but works fine inserting " Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332657 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 what ? is this solved already? Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332665 Share on other sites More sharing options...
jpratt Posted August 24, 2007 Author Share Posted August 24, 2007 no, im still getting an error when a ' is entered. I tried using addslashes but still get the error. addslashes worked for " but not ' Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332686 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 http://www.php.net/manual/en/function.htmlspecialchars.php try Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332688 Share on other sites More sharing options...
jpratt Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks, that did it. Link to comment https://forums.phpfreaks.com/topic/66444-solved-format-string/#findComment-332731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.