dmccabe Posted December 11, 2008 Share Posted December 11, 2008 How do you insert data in to a data base when the data you are submitting has " and ' in it? I am wanting to put lots of lines like this: HKUS\S-1-5-19\..\Run: [startUp This] "C:\Program Files\Laplink\PCmover\LaunchSt.exe" (User 'LOCAL SERVICE') Link to comment https://forums.phpfreaks.com/topic/136469-inserting-in-to-a-database/ Share on other sites More sharing options...
dmccabe Posted December 11, 2008 Author Share Posted December 11, 2008 Sorry the error I am getting is this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LOCAL SERVICE') ','1')' at line 1 Link to comment https://forums.phpfreaks.com/topic/136469-inserting-in-to-a-database/#findComment-712301 Share on other sites More sharing options...
xProteuSx Posted December 11, 2008 Share Posted December 11, 2008 You can escape some characters by putting a '\' in front of them. For example: echo 'You can't do this.'; Would bring up an error, but if you do this, it will work: echo 'You can\'t do this.'; When you view the text it will show up as: You can't do this. Link to comment https://forums.phpfreaks.com/topic/136469-inserting-in-to-a-database/#findComment-712311 Share on other sites More sharing options...
dmccabe Posted December 11, 2008 Author Share Posted December 11, 2008 Thanks proteus, but how do I add the slashes if that value is being read from a file? The whole thing: HKUS\S-1-5-19\..\Run: [startUp This] "C:\Program Files\Laplink\PCmover\LaunchSt.exe" (User 'LOCAL SERVICE') Is read in from a txt file and then each line is put in to a variable? Link to comment https://forums.phpfreaks.com/topic/136469-inserting-in-to-a-database/#findComment-712360 Share on other sites More sharing options...
redarrow Posted December 11, 2008 Share Posted December 11, 2008 you use the mysql database functions.. example <?php // addslashes() // stripslashes() // mysql_real_escape_string() //example. //Making database posted variables safe for a mysql database. $redarrow=addslashes($_POST['redarrow']); $redarrow=stripslashes($_POST['redarrow']); $redarrow=mysql_real_escape_string($_POST['redarrow']); ?> Link to comment https://forums.phpfreaks.com/topic/136469-inserting-in-to-a-database/#findComment-712373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.