Jump to content

Recommended Posts

Hi, thanks ahead of time to anyone who takes the time to read this.

 

I have a php script that creates a php file with user-specified content. THis is all well and good, however, I wish to include a php script within the content of the created file.

 

I run into the problem when I insert php tags, to specify php code, in the $content variable of the file.

 

Is there a way I can insert a small snippet of php when creating a file? (So the created file will have the php code in it, as php when it is created.)

 

Thanks, I will be glad to clarify if this if it's hard to follow.

Link to comment
https://forums.phpfreaks.com/topic/53212-solved-writing-php-to-a-php-file/
Share on other sites

<?php
echo
"<form method="post" action="/create.php">     
<p>Password: <input type="password" name="truepassword" size="30"/></p><BR>
<p><input type="submit" value="Submit"/></p>
</form>
";		  		  

if ($truepassword = $des_password)
{
echo "Password Correct";
}
else
{
echo "Login to edit your profile";
}
?>

<center>
Username: one<BR>
Password: \'\'<BR>
True Password: <BR>
Des Password: \'\'<BR>

Other Information: 

 

This is the output of create.php which creates the file with the above contents. When I try to view this file through the browser, I get an "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../one.php on line 3"

 

(The "..." is the dir/path to the file, which shouldn't be needed to work the problem..)

 

I have worked on trying to solve this problem since your first reply... No luck. I don't understand where it expects the "," or ";", I am trying to have the created page echo an html form where it can process a password.

 

(Note that the action=/create.php will change to something like action=<? PHP_SELF?> sometime later on, since it is itself that will process the info from the form... If I can get the form working....)

problem you have is you're using double quotes too much...

 

echo
"<form method="post" action="/create.php">     
<p>Password: <input type="password" name="truepassword" size="30"/></p><BR>
<p><input type="submit" value="Submit"/></p>
</form>
";

 

should be

 

echo
'<form method="post" action="/create.php">     
<p>Password: <input type="password" name="truepassword" size="30"/></p><BR>
<p><input type="submit" value="Submit"/></p>
</form>
';

 

(note the quotes)

 

it should also be "$truepassword == $des_password"

Then I get

Parse error: syntax error, unexpected T_STRING in .../create.php on line 164

 

Code segment for /create.php:

 

(Line 161) $content = '
(Line 162) <?php
(Line 163) echo
(Line 164) '<form method="post" action="/create.php">
(Line 165) <p>Password: <input type="password" name="truepassword" size="30"/></p><BR>
(Line 166) <p><input type="submit" value="Submit"/></p>
(Line 167) </form>
(Line 168) ';		

   

 

the problem is that you're using a single quote and then using a single quote within your $content, so it can't tell where you want the variable assignment to end and the rest of the code to continue, here's an article on escaping quotes...

http://www.hudzilla.org/phpbook/read.php/2_6_2

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.