robcrozier Posted August 23, 2006 Share Posted August 23, 2006 hi, im trying to input some text into a mysql text field using php. Though everytime i use a ' in my text i get an error. Here is the code that i'm using to insert the data into the table:[code] $query = "update stock set title = '$t', description = '$d', price = '$p' where id = '$i'";[/code]How can i tweak this to allow me to input inverted commas ( ' ) in the description and title fields?Thanks! Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/ Share on other sites More sharing options...
hitman6003 Posted August 23, 2006 Share Posted August 23, 2006 They are single quotes. You have two options. Use addslashes (http://www.php.net/addslashes) or use mysql_real_escape_string (http://www.php.net/mysql_real_escape_string) on the var that is giving you trouble (not the whole query) Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/#findComment-79215 Share on other sites More sharing options...
robcrozier Posted August 23, 2006 Author Share Posted August 23, 2006 thanks mate thats done the trick!!! ;DHowever, i now have one more question: - Can you use a similar function to get mysql to accept commas and print them out when used in an INT field? At the min whenever i enter one, all of the data that follows it is not displayed.thanks again! Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/#findComment-79239 Share on other sites More sharing options...
SharkBait Posted August 23, 2006 Share Posted August 23, 2006 I also use [code=php:0] str_replace("'", "\'", "There's a tree"); [/code] Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/#findComment-79243 Share on other sites More sharing options...
SharkBait Posted August 23, 2006 Share Posted August 23, 2006 INT field is an integer 1493 is an INT1,493 is technically a stringYou would have to format the output to display the comma for you. Unless of course there is a particular function that I am unaware of to format numbers like that for you. I know there is one for formating decimals.... Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/#findComment-79245 Share on other sites More sharing options...
kenrbnsn Posted August 23, 2006 Share Posted August 23, 2006 Use the function number_format() to format numbers. http://www.php.net/number_formatKen Link to comment https://forums.phpfreaks.com/topic/18423-using-in-mysql/#findComment-79295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.