...

View Full Version : Having a parse error in line 40 can someone please help



rose34ll2
04-22-2012, 03:22 AM
<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['AreaCode'] . ")" . @$_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 = 'file.txt';
$Contact = fopen($NewContact, 'a+');
$output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum');
echo "<p>Contact Saved Successfully</p>";
fwrite($Contact, $output);

if ( @$_GET['source'] ){
show_source(__FILE__);
die();
}

// Open text file
$Contact = fopen("file.txt", "rb");

// read text file into $contents
$contents = "";
while (!feof($Contact)) {
$contents .= fread($Contact, 8192);
}

// close the file
fclose($Contact);

echo nl2br($contents);

echo "<hr>";


// Sepeate $contents
$contactLines = explode("\n", $contents);
echo "<pre>"; print_r($contactLines); echo "</pre>";


echo "<hr>";


// Sort the array
asort($contactLines);
echo "<pre>"; print_r($contactLines); echo "</pre>";


echo "<hr>";



?>
<table>
<tr>
<th>Name</th>
<th>AreaCode</th>
<th>Phone</th>
</tr>

<?
// output the data
foreach($contactLines as $line){
$info = explode(",", $line);
$LastName = $info[0];
$FirstName = $info[1];
$AreaCode = $info[2];
$PhoneNum = $info[3];
echo '<tr>';
echo '<td><input type="text" value="'.$LastName.', '.$FirstName.'"></td>';
echo '<td><input type="text" value="'.$AreaCode.', '.$PhoneNum.'"></td>';

echo '</tr>';
}


?>
</table>
<?




echo "<hr>";

echo nl2br("

fclose($Contact);

?>

<p><a href="unit4.html">Add New Listing</a></p>
<p><a href="file.txt">Retrieve Contact List</a></p>

</body>
</html>

_Aerospace_Eng_
04-22-2012, 03:28 AM
Look at line 40. It is pretty obvious. Also using a IDE that has syntax highlighting makes it even more obvious.

$output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum');
echo "<p>Contact Saved Successfully</p>";
Remove the '), replace it with \n"

rose34ll2
04-22-2012, 04:30 AM
Look at line 40. It is pretty obvious. Also using a IDE that has syntax highlighting makes it even more obvious.

$output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum');
echo "<p>Contact Saved Successfully</p>";
Remove the '), replace it with \n"

Hi thankyou I did that and nows its sayng the echo moved down to line 40

Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\unit4.php on line 40

_Aerospace_Eng_
04-22-2012, 04:59 AM
Post your new code. You likely forgot the semi-colon. I suggest you read the php manual. php.net

Your questions are pretty basic.

djm0219
04-22-2012, 08:45 AM
Look closely at the end of that line.



$output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum');
echo "<p>Contact Saved Successfully</p>";

Replace $PhoneNum'); with $PhoneNum";


$output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum";
echo "<p>Contact Saved Successfully</p>";

rose34ll2
04-22-2012, 02:42 PM
Tyyy DJ trying that now , I am new to php and trying to learn this and I was in tears last nite kept messing with that code trying everything to fix it..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum