Forum Home
Press F1
 
Thread ID: 66400 2006-02-21 12:06:00 Need help with PHP script Adam678 (6880) Press F1
Post ID Timestamp Content User
1357757 2006-02-21 12:06:00 I'm trying to setup a very simple update feature. The user enters or updates information into a textarea then when submitted the information is sent to a html file where it is stored. Below is what I have done so far:

index.php

<?php
$filename="test.htm";
$fd=fopen($filename,"r");
$textFileContents=fread($fd,filesize($filename));
fclose($fd);

if ($subfrm) {
$fd=fopen("test.htm","w");
fwrite($fd, $newdata);
fclose($fd);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="index.php" method="post">
<div align="center"><span class="style2">Test</span><br>
<textarea name="newdata" rows="15" cols="70"><?php include ("test.htm"); ?>
</textarea>
<br>
<input name="subfrm" type="submit" id="subfrm" value="submit">
<input type="reset" name="Reset" value="Reset">
</div>
</form>
</body>
</html>

The second file is test.htm, this is a blank html file stored in the same directory as index.php, it has a CHMOD of 777 so information can be submitted to it.

The problem I'm having is HTML coding is not able to be submitted to the html file, it only allows text. the problems lies in the PHP script at the top of the index.php page:

<?php
$filename="test.htm";
$fd=fopen($filename,"r");
$textFileContents=fread($fd,filesize($filename));
fclose($fd);

if ($subfrm) {
$fd=fopen("test.htm","w");
fwrite($fd, $newdata);
fclose($fd);
}
?>
but being new to PHP I don't know what changes I have to make to allow HTML coding to be submitted, any suggestions?

Thanks
Adam678 (6880)
1357758 2006-02-21 12:35:00 not sure, too late, but you may have to get them to put a slash infront of all the non-text eg. /< or /"

or

try the &nbsp; or alt codes
Rob99 (151)
1357759 2006-02-21 19:41:00 Try having a look at php.inspire.net.nz

Would reading/writing to a database be better/easier?

Can you give us an example of what goes wrong?
mejobloggs (264)
1357760 2006-02-21 23:19:00 Hang on here.. you can't have HTML tags in a textarea input (well you can but a web browser won't do anything with them).
You could apply CSS styles to it though......
gibler (49)
1