I think something is wrong.
my hit counter is going 2, 4, 6, 8, 10....That makes no sense.
whenever i use fwrite(), each of my lines retrieved from a form are written twice and I have duplicates....
data1
data1
data2
data2
I also have strange commas being inserted randomly.
My code says no errors in Zend.
Can someone please help me? I am using MAMP and PHP5.
Here is relevant code, each time I'm getting what I'm calling "duplicate" errors.
<form action="guestBook.php" method="get">
<p>Name: <input type="text" name="name" id="name" size="20" /></p>
<p>Email Address: <input type="text" name="email" id="email" size="20" /></p>
<p><input type="submit" value="enter" /><input type="reset" /></p>
</form>
<?php
$name = $_GET['name'];
$email = $_GET['email'];
$info = $name . "~" . $email;
$guestBook = "guestbook.txt";
$guestBookHandle = fopen($guestBook, "a");
if (fwrite($guestBookHandle, $info) > 0)
echo "<p>Your info has been recorded successfully.</p>";
else
echo "<p>Unsuccessfuly writing to file.</p>";
fclose($guestBookHandle);
?>
<?php
$CounterFile = "hitcount.txt";
if (file_exists("hitcount.txt"))
{
$hits = file_get_contents("hitcount.txt");
++$hits;
}
else
$hits = 1;
echo "There have been $hits hits to this page!";
if (file_put_contents("hitcount.txt", $hits))
echo "The counter file has been updated.";
?>
<form action="Healthconference.php" method="post" enctype="application/x-www-form-urlencoded">
<p><label for="name">Name: </label><input type="text" name="name" id="name" size="20" /></p>
<p><label for="address">Address: </label><input type="text" name="address" id="address" size=35" /></p>
<p><label for="city">City: </label><input type="text" name="city" id="city" value="San Francisco" size="15" /></p>
<p><label for="state">State: </label><input type="text" name="state" id="state" value="California" size="12" /></p>
<p><label for="zip">Zipcode: </label><input type="text" name="zip" id="zip" size="5" maxlength="5" /></p>
<p>Do you want meals provided (extra charge)?</p>
<p><input type="radio" name="meals" id="yes" value="yes" /><label for="yes">Yes</label></p>
<p><input type="radio" name="meals" id="no" value="no" /><label for="no">No</label></p>
<p><input type="submit" value="register me" /><input type="reset" value="reset form" /></p>
</form>
<?php
echo "here";
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$registrationFile = fopen("registration.txt", "w");
$guestInfo = $name . ",";
$guestInfo .= $address . ",";
$guestInfo .= $city . ",";
$guestInfo .= $state . ",";
$guestInfo .= $zip; . "\n";
if (fwrite($registrationFile, $guestInfo) > 0)
echo "<p>You have been registered!</p>";
else
echo "<p>Could not write to file.</p>";
fclose($registrationFile);
?>