This is a project for a class. I'm unable to figure it out and I'm at my wits end. I'm not asking for someone to do the project to me, just tell me where my coding is wrong. My html form is correct. I just placed in on here for a reference. My php code seems to work until I get to the // Split a string into an index array. Any help would be greatly appreciated.
When I try to run the program through WAMP I get an error:
Parse error: parse error in
C:wampwwwOswaltPatricia_Unit4AssignmentSaveDirectory.php on line
53
Line 53 is:
$Contacts = "$LastName;$FirstName;$StreetAdd;$City;$State;$ZipCode;$AreaCode;$PhoneNum";
InputTelephone.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<!--Patricia Oswalt - IT250 Unit 4 Assignment-->
<head>
<title>Telephone Directory Input</title>
</head>
<body>
<h1>New Directory Listing</h1>
<form action="SaveDirectory.php" method="post" enctype="application/x-www-form-urlencoded">
<p>Last Name <input type="text" name="LastName" size="30" tabindex="1" />
First Name <input type="text" name="FirstName" size="20" tabindex="2" /></p>
<p>Street Address <input type="text" name="StreetAdd" size="50" tabindex="3" /></p>
<p>City <input type="text" name="City" size="30" tabindex="4" />
State (Abbr) <input type="text" name="State" size="2" tabindex="5" />
Zip Code<input type="text" name="ZipCode" size="5" tabindex="6" /></p>
<p>Area Code (<input type="text" name="AreaCode" size="3" tabindex="7"/>)
Phone Number <input type="text" name="PhoneNum" size="8" tabindex="8" /></p>
<p><input type="submit" value="Save" tabindex="9" /><input type="reset" tabindex="10" /></p>
</form>
<p><a href="InputTelephone.html">Add New Listing</a></p>
<p><a href="contactlist.txt">Retrieve Contact List</a></p>
</body>
</html>
SaveDirectory.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<!--Patricia Oswalt - IT250 Unit 4 Assignment-->
<head>
<title>Save Directory</title>
</head>
<body>
<?php
//initializing the variables
$LastName = ($_POST['LastName']);
$FirstName = ($_POST['FirstName']);
$StreetAdd = ($_POST['StreetAdd']);
$City = ($_POST['City']);
$State = ($_POST['State']);
$ZipCode = ($_POST['ZipCode']);
$AreaCode = ($_POST['AreaCode']);
$PhoneNum = ($_POST['PhoneNum']);
//confirming that all variables will contain values
if (empty($LastName) ||
empty($FirstName) ||
empty($StreetAdd) ||
empty($City) ||
empty($State) ||
empty($ZipCode) ||
empty($AreaCode) ||
empty($PhoneNum))
echo "<p>You must completely fill out the form. Please use your browser's Back button to return to the form.</p>";
else
//creating, writing and saving to the text file.
$NewContact = 'contactlist.txt';
$Contact = fopen($NewContact, 'a+');
$output ="n $LastName n";
$output ="n $FirstName n";
$output ="n $StreetAdd n";
$output ="n $City n";
$output ="n $State n";
$output ="n $ZipCode n";
$output ="n $AreaCode n";
$output ="n $PhoneNum n";
echo "New Contact Saved Successfully!";
fwrite($Contact, $output);
fclose($Contact)
// Split a string into an index array
$Contacts = "$LastName;$FirstName;$StreetAdd;$City;$State;$ZipCode;$AreaCode;$PhoneNum";
$ContactsArray = explode(";", $Contacts);
echo "<br><strong>Contact List</strong><br><br>";
for($i=0; $i<count($ContactsArray); $i++) {
echo "$ContactsArray[$I]<br>";
}
// Sort an index array
sort($ContactsArray);
echo "<br><strong>Sorted Contact List</strong><br><br>";
foreach($ContactsArray as $Contacts) {
echo "$Contacts<br>";
}
?>
</body>
</html>
Software/Hardware used:
CodeLobsterPHP edition; PHP 5.3.0; WAMP; FireFox; MS Windows XP Pro
ASKED:
March 11, 2010 6:21 PM
UPDATED:
April 5, 2010 4:15 PM
Thank you, CarlosDL. That got rid of the parsing error. Such a little thing that causes such a big problem. Unfortunately, I am not completely out of the woods yet. The text file that is created by this application is supposed to save all of the contact information entered and append when necessary. It is only saving the phone number. Any other suggestions?
Really appreciate the help. I’ve been working on this one project for nearly two weeks.
Patricia
Ah. forget it. I figured out the answer myself. YEAH! Thanks again.
Great !
You are welcome.