Page 1 of 1

T_CONSTANT_ENCAPSED_STRING

Posted: Mon Aug 28, 2006 7:30 pm
by webchimp
I'm getting the following error
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/*****/public_html/*****/uploadingimg2.php on line 42
Everything around and above this line hasn't been changed in awhile, I've only made some changes later on in the code.

I've done a search and there in an equal number of [`] ['] and ["] throughout the code, so it's not an odd one out.

Code: Select all

<html>
    <head>
        <title>
            Image upload test site: Upload and confirm
        </title>
    </head>

    <body>
        <?php
            //Common header
            include "header.inc";
        ?>

        <h3>
            Uploading File.
        </h3>

        <?php
            //Assign something from somewhere
            $picture = $_FILES["mainPic"]["name"];
            $thumbnail = $_FILES["thumbPic"]["name"];
            $description = $_POST["picDesc"];

            //Directory to upload file
            $uploadDir = "pics/";

            //Database to log into
Line 42>    $database = mysql_connect "*****", "*****", "*****";

            if(!empty($_FILES["mainPic"]))
            {
                //Upload main pic and get the id number of the database entry.
                $pictureId = uploadMainPic($picture, $uploadDir, $database);
                uploadThumbnail($thumbnail, $uploadDir, $database, $pictureId);
                uploadDescription($description, $database, $pictureId);
            }
            else
            {
                //Display error message
                echo "Error!";
                echo "<br / >";
                echo "<a href = \"uploadingimg.php\">Back</a>";
            }
/******************************************************************************
End of main code
******************************************************************************/

/******************************************************************************
Functions
******************************************************************************/
            /******************************************************************
            function: uploadMainPic
            This function checks for and uploads the main image.
            ******************************************************************/
            function uploadMainPic($picture, $uploadDir, $database)
            {
                //Upload the file
                if (move_uploaded_file($_FILES["mainPic"]["tmp_name"], $uploadDir . $_FILES["mainPic"]["name"]))
                {
                    //Database to insert the file details into.
                    mysql_select_db "*****",$database);

                    //Insert file into the database table 'pics', so it can be accessed.
                    mysql_query "INSERT INTO `pics` ( `id` , `image` , `thumb` , `desc` ) VALUES ('', '$picture', '', '');",$database);

                    //Scan entries in database to find the id number of the pic just uploaded.

                    //Get entries in database and put them in an array
                    $picArray = mysql_query "select * from pics order by id", $database);

                    //Find out how many rows in the array
                    $rows = mysql_num_rows($picArray);

                    //Step through the array to find an entry that matches the pic just uploaded and get the id number
                    for ($count=0; $count < $rows; $count++)
                    {
                        $myrow = mysql_fetch_row($picArray);

                        if ($myrow[1] == $picture)
                        {
                            $pictureId = $myrow[0];
                        }
                    }
                }
                else
                {
                    //Display error message
                    echo "Error!";
                    echo "<br / >";
                    echo "<a href = \"uploadingimg.php\">Back</a>";
                }

                return $pictureId;
            }
            /******************************************************************
            end function: uploadMainPic
            ******************************************************************/

            /******************************************************************
            function: uploadThumbnail
            This function adds the thumbnail.
            ******************************************************************/
            function uploadThumbnail($thumbnail, $uploadDir, $database, $pictureId)
            {
                //Upload the file
                if (move_uploaded_file($_FILES["thumbPic"]["tmp_name"], $uploadDir . $_FILES["thumbPic"]["name"]))
                {
                    //Database to insert the file details into.
                    mysql_select_db "*****",$database);

                    //Modify the entry for the pic just uploaded and enter the thumbnail file into the database table 'pics', so it can be accessed.
                    mysql_query "update pics set thumb = '$thumbnail' where id = '$pictureId'", $database);
                }
                else
                {
                    //Display error message
                    echo "Error!";
                    echo "<br / >";
                    echo "<a href = \"uploadingimg.php\">Back</a>";
                }
            }
            /******************************************************************
            end function: uploadThumbnail
            ******************************************************************/

            /******************************************************************
            function: uploadDescription
            This function adds the picture description.
            ******************************************************************/
            function uploadDescription($description, $database, $pictureId)
            {
                //Database to insert the description into.
                mysql_select_db "*****",$database);

                //Modify the entry for the pic just uploaded and enter the description into the database table 'pics', so it can be accessed.
                mysql_query "update pics set desc = '$description' where id = '$pictureId'", $database);
            }
            /******************************************************************
            end function: uploadDescription
            ******************************************************************/
/******************************************************************************
End functions
******************************************************************************/
        ?>
    </body>
</html>

Posted: Mon Aug 28, 2006 7:34 pm
by webchimp
Almost thought I had it, found 18 open '(' and 25 close ')'.
Edited the code and uploaded it... still errored :(
Then noticed I han't saved the edited version, saved and re-uploaded... Still does not work :cry:

Then (again) I realised I hadn't put the brackets back on this line

Code: Select all

$database = mysql_connect "*****", "*****", "*****";
Doh!

All fixed now. :roll:

Problem came when I borroed (ahem!) some code off a mate who does his echo statments with brackets and quotes. So when I was tidying up the code for the final working version I did a search and replace for all the [("] and [")] and replace them with just ["].

Must be more carefull in future.

Posted: Mon Aug 28, 2006 7:35 pm
by RobertGonzalez
Try mysql_connect() (with the parentheses).