Jump to content

File Write " and ' closing early issu


kiksy

Recommended Posts

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!

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/201347-file-write-and-closing-early-issu/
Share on other sites

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);

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!  8)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.