Jump to content

Recommended Posts

Ok im new to php and am trying to make this script to work

If it helps the error i get is "PHP Parse error:  syntax error, unexpected T_VARIABLE in C:\\web\\htdocs\\Filey\\create.php on line 3"

-------------------------------------------------------------

form.php

---------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="bv_Form1" style="position:absolute;left:34px;top:34px;width:669px;height:221px;z-index:2;" align="left">
<form name="Form1" method="POST" action="create.php" id="Form1">
<input type="text" id="Editbox1" style="position:absolute;left:24px;top:24px;width:565px;font-family:Courier New;font-size:16px;z-index:0" name="fname" value="name1">
<input type="submit" id="Button1" name="Button1" value="Submit" style="position:absolute;left:266px;top:126px;width:75px;height:24px;font-family:Arial;font-size:13px;z-index:1">
</form>
</div>
</body>
</html>

-------------------------------

code for create.php

---------------------------------------

<?php

$hell = $_POST["fname"]

$myFile = "t.txt";

$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "$hell\n";

fwrite($fh, $stringData);

fclose($fh);

?>

------------------------------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/187752-writing-a-file-with-php-from-a-form/
Share on other sites

i changed it and now it does not work again

 

create.php

----------------------------------------------------

<?php
$head1 = "<html>";
$head2 = "<head>";
$head3 = "<title>";
$head4 = "</title>";
$head5 = "</head>";
$head6 = "</html>";
$hell = $_POST["fname"]; 
$myFile = "html.html";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$head1";
$stringData2 = "$head2";
$stringData3 = "$head3";
$stringData4 = "$hell";
$stringData5 = "$head4";
$stringData6 = "$head5";
$stringData7 = "$head6";
fwrite($fh, $stringData\n);
fwrite($fh, $stringData2\n);
fwrite($fh, $stringData3\n);
fwrite($fh, $stringData4\n);
fwrite($fh, $stringData5\n);
fwrite($fh, $stringData6\n);
fwrite($fh, $stringData7\n);
fclose($fh);
?>

-----------------------------------------------

Form.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="GENERATOR" content="Created by BlueVoda">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="bv_Form1" style="position:absolute;left:33px;top:35px;width:669px;height:388px;z-index:2;" align="left">
<form name="Form1" method="POST" action="create.php" id="Form1">
<input type="submit" id="Button1" name="Button1" value="Submit" style="position:absolute;left:264px;top:336px;width:75px;height:24px;font-family:Arial;font-size:13px;z-index:0">
<input type="text" id="Editbox1" style="position:absolute;left:62px;top:110px;width:533px;font-family:Courier New;font-size:16px;z-index:1" name="fname" value="">

</form>
</div>
</body>
</html>

$fh = fopen($myFile, 'w') or die("can't open file");

 

the 'w' means that you are overwriting the file.  'r' means read only and 'a' means append.  So, if I understand what

is happening here- each time you fwrite($fh, $stringData\n);- it is over writing the file so in the end it will only contain the

last variable listed which is $stringdata7.

 

What is it you are wanting to do?  How do you want to use this file?

Like Dennis Hopper said "simplify man"

 

<?php
$stringData = "<html>\n";
$stringData .= "<head>\n";
$stringData .= "<title>\n";
$stringData .= $_POST['fname'];
$stringData .= "</title>\n";
$stringData .= "</head>\n";
$stringData .= "</html>\n";
$myFile = "html.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $stringData);
fclose($fh);
?>

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.