Could someone run this code for me?
I simply can't do anything correctly with files.
They are written to twice and I simply don't get why. Is it a problem with php.ini files. Incidentally, this code says it's fine in Zend. I am using PHP 5 wamp server 2.0
Can someone tell me what the best settings are so that I can just program and not have to worry so much about the right settings?
<!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>Telephone Directory</title>
<link rel="stylesheet" href="#" type="text/css" />
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Telephone Directory Main Page</h1>
<form action="telephoneDirectory.php" method="get" enctype="application-x-www-form-urlencoded">
<fieldset>Enter Your Information
<h4>Name: <input type="text" name="name" id="name" size="20" />
Address: <input type="text" name="address" id=" address" size="20" /></h4>
<h4>City: <input type="text" name="city" id="city" size="20" />
State <input type="text" name="state" id="state" size="2" /></h4>
<h4>Telephone Number (10 digits)</label><input type="text" name="number" id="number" size="10" maxlength="10" /></h4>
<p><input type="submit" value="submit" /><input type="reset" value="clear" /></p>
</fieldset>
</form>
<h2><a href="viewTelephoneDirectory.php" alt="view all numbers">View All Telephone Numbers</a></h2>
if (isset($_GET['name']) && isset($_GET['address']) && isset($_GET['city']) && isset($_GET['state']) && is_numeric($_GET['number']))
{
$name=$_GET['name'];
$address = $_GET['address'];
$city = $_GET['city'];
$state = $_GET['state'];
$number = $_GET['number'];
$info = addslashes($name . "~" . $address . "~" . $city . "~" . $state . "~" . $number . "\r\n");
$infoHandle = fopen("directory.txt", "a");//opened for writing
if (flock($infoHandle, LOCK_EX))
{
if (is_writable("directory.txt"))
{
if(fwrite($infoHandle, $info) > 0)
echo "<p>Successfully added your entry!</p>";
else
echo "<p>Couldn't register you. Sorry.</p>";
}
else
echo "<p>This file is not writeable.</p>";
}
else
echo "<p>Sorry, file is locked.</p>";
}
else
echo "<p>You must fill in the form completely and enter only 10 digits for a phone number</p>";
<hr />
</body>
</html>
<!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>View All Numbers</title>
<link rel="stylesheet" href="#" type="text/css" />
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h2>Here Are all The Numbers In Alphabetical Order</h2>
if (file_exists("directory.txt"))
{
if (is_readable("directory.txt"))
{
//$directoryHandle = fopen("directory.txt", "a");
$directoryArray = file("directory.txt");
for ($i = 0; $i < count($directoryArray); $i++)
{
$individualArray = explode("~", $directoryArray[$i]);
foreach ($individualArray as $field)
echo $field . "\n";
}
}
else
echo "<p>Sorry, can't read from directory.</p>";
}
else
echo "<p>Sorry, there are no numbers yet. Please enter one first.</p>";
<hr />
</body>
</html>