kiksy Posted May 11, 2010 Share Posted May 11, 2010 Hi there, Ive searched around , but due to the grammatical style of my problem its been hard to find an answer on Google or here. I am inserting some PHP/MySQL commands into a new .php file using 'fwrite' : $stringData = '"; $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = "'; fwrite($fh, $stringData); $stringData = '$idselect'; fwrite($fh, $stringData); $stringData = '"); When run the resulting .php file contains : $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = "$idselect""); Where as it needs to be : $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = '$idselect'"); with '' instead of "" around $idselect. The issue is that when I put ' around $stringData = '$idselect'; in the first page it closes it. I hope Ive explained my issue clearly, thanks in advance for any help, Im sure its a simple fix! Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/ Share on other sites More sharing options...
Adam Posted May 11, 2010 Share Posted May 11, 2010 Escape the single quotes with a backslash. For example.. $str = 'it\'s'; Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/#findComment-1056329 Share on other sites More sharing options...
scept1c Posted May 11, 2010 Share Posted May 11, 2010 well Kiksy doesn't use slash here. Or I misunderstood the suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/#findComment-1056336 Share on other sites More sharing options...
Adam Posted May 11, 2010 Share Posted May 11, 2010 well Kiksy doesn't use slash here. Or I misunderstood the suggestion. I believe he was having troubles trying to achieve the second output; with single quotes closing the string.. Basically using a single quote within single-quoted string. If I've confused you, this should work for you kiksy: $stringData = '$dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = \'$idselect\'");'; fwrite($fh, $stringData); Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/#findComment-1056337 Share on other sites More sharing options...
kiksy Posted May 11, 2010 Author Share Posted May 11, 2010 Thanks, I was jut away entering what you suggested when you put that second post down. It works perfectly with : $stringData = '"; $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = '; fwrite($fh, $stringData); $stringData = '\'$idselect\''; fwrite($fh, $stringData); Thanks for the quick response! Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/#findComment-1056340 Share on other sites More sharing options...
Adam Posted May 11, 2010 Share Posted May 11, 2010 Ah, of course in your example you could just use: $stringData = "'$idselect'"; Quote Link to comment https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/#findComment-1056342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.