Reputation: 11
I have written a PHP script to run with HTML that takes the text entered into a textbox and place it in a text file, however, the code does not work and I cannot figure out why. I'm fairly new to PHP and it would be great if somebody could help :D
<!DOCTYPE HTML>
<html>
<head>
<title>Altering text files</title>
</head>
<body>
<form name ="form1" method ="post" action = "">
<input type = "text" name = "string">
<input type = "submit" name = "submit" value = "Add text">
</form>
</body>
</html>
<?php
$file = "./lines.txt";
$write = $_POST['string']
file_put_contents($file , $write, FILE_APPEND);
?>
Upvotes: 1
Views: 887
Reputation: 852
<!DOCTYPE HTML>
<html>
<head>
<title>Altering text files</title>
</head>
<body>
<form name ="form1" method ="post" action = "">
<input type = "text" name = "string">
<input type = "submit" name = "submit" value = "Add text">
</form>
</body>
</html>
<?php
if(isset($_POST))
{
var_dump($_POST);
echo 'foo!';
/*$file = "./lines.txt";
$write = $_POST['string'];
file_put_contents($file , $write, FILE_APPEND);*/
}
?>
test it to see if something is printed
Upvotes: 1
Reputation: 318
try to add semicolon after $_POST['string'] also try display errors to know if anything is going wrong
Upvotes: 0