Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Having a parse error in line 40 can someone please help

    PHP Code:
      <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>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Look at line 40. It is pretty obvious. Also using a IDE that has syntax highlighting makes it even more obvious.
    PHP Code:
             $output "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum'); 
             echo "
    <p>Contact Saved Successfully</p>"; 
    Remove the '), replace it with \n"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Look at line 40. It is pretty obvious. Also using a IDE that has syntax highlighting makes it even more obvious.
    PHP Code:
             $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

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post your new code. You likely forgot the semi-colon. I suggest you read the php manual. php.net

    Your questions are pretty basic.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Look closely at the end of that line.

    PHP Code:
    $output "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum');
    echo "
    <p>Contact Saved Successfully</p>"; 
    Replace $PhoneNum'); with $PhoneNum";

    PHP Code:
    $output "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $AreaCode, $PhoneNum";
    echo 
    "<p>Contact Saved Successfully</p>"
    Dave .... HostMonster for all of your hosting needs

  • #6
    New Coder
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •