php_beginner_83 Posted September 18, 2009 Share Posted September 18, 2009 Hi All I'm trying to create an upload page (form) where I can add photos (the path of the image) and a description of the photo to a database. I'm coming across problems when in the 'description'. If I use ' it creates an error, for example, 'I'm a bear'. When I use Im a bear, there is no problem. I'm still fairly new to php and would appreciate any comments on this. My code is.. $insert = "INSERT INTO pictures (ID, Description, Path) VALUES ($newID, '{$_POST['imageDescription']}', '" . $string . "{$_POST['path']}')"; mysql_query($insert) or die(mysql_error()); It's this insert where the problem is. Thank you. Link to comment https://forums.phpfreaks.com/topic/174758-solved-problems-with-insert-and-apostrophes/ Share on other sites More sharing options...
zq29 Posted September 18, 2009 Share Posted September 18, 2009 mysql_real_escape_string() Link to comment https://forums.phpfreaks.com/topic/174758-solved-problems-with-insert-and-apostrophes/#findComment-920966 Share on other sites More sharing options...
php_beginner_83 Posted September 18, 2009 Author Share Posted September 18, 2009 Should $insert go into that function or just the part that contains the apostrophes i.e. $_POST['imageDescription'] Thanks Link to comment https://forums.phpfreaks.com/topic/174758-solved-problems-with-insert-and-apostrophes/#findComment-920967 Share on other sites More sharing options...
kickstart Posted September 18, 2009 Share Posted September 18, 2009 Hi Just the part with the apostraphies $insert = "INSERT INTO pictures (ID, Description, Path) VALUES ($newID, '".mysql_real_escape_string($_POST['imageDescription'])."', '" . $string . mysql_real_escape_string($_POST['path'])."')"; All the best Keith Link to comment https://forums.phpfreaks.com/topic/174758-solved-problems-with-insert-and-apostrophes/#findComment-920970 Share on other sites More sharing options...
php_beginner_83 Posted September 19, 2009 Author Share Posted September 19, 2009 Thanks Keith, that worked a treat Link to comment https://forums.phpfreaks.com/topic/174758-solved-problems-with-insert-and-apostrophes/#findComment-921297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.