Hi everyone.. I keep having an error in the following code..
Please bear with me I am a serious Newbie, cant work out what I got wrong Thanks
Its a simple code to try and write to a txt file.. Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Guest Book</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h2>Enter the Book you want to Add</h2>
<form method="get" action="addBook.php">
<p>Book Name <input type="text" name="book_name" /></p>
<p>Author <input type="text" name="author_name" /></p>
<p>ISBN <input type="text" name="isbn" /></p>
<p>Price <input type="text" name="price" /></>
<p><input type="submit" value=" Submit Book "';
p><input type="submit" value=" Clear Values" /></p>
</form>
<?php
if (isset($_GET['book_name']) || isset($_GET['author_name']) ||isset($_GET['isbn']) || isset($_GET['price']))
{
$BookName = addslashes($_GET['book_name']);
$Author = addslashes($_GET['author_name']);
$Isbn = addslashes ($_GET['isbn']);
$price = addslashes ($_GET['price']);
submit($BookName,$Author,$Isbn,$price);
}
else
{
echo "<p>You must enter all values for the book! Click your browser's Back button to return to the RSVP form.</p>";
}
function submit($BookName,$Author,$Isbn,$price) {
$Book = "";
umask(0007);
$filename = "books.txt";
if (!file_exists($filename)){
//mkdir("c:\data/lab05", 02777);
$Book = fopen($filename, "a");
}
if (is_writable($filename)) {
if (fwrite($Book, $BookName . ", " . $Author . ", " . $Isbn . ", " . $price . "\n"))
echo "<p>Thank you for signing our guest book!</p>";
else
echo "<p>Cannot add your name to the guest book.</p>";
}
else{
echo "<p>Cannot write to the file.</p>";
fclose($Book);
}
}
?>
</body>
</html>