Hello, I would like to know what syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING means?

I would to know this way I can understand how to fix these errors when they appear.

What is "T_ENCAPSED_AND_WHITESPACE"?
What is "T_STRING or T_VARIABLE or T_NUM_STRING"

Thank you in advance!

    funkymonkey;10983353 wrote:

    I would like to know what syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING means?

    It means that the PHP parser couldn't understand how to parse your PHP code into something that the interpreter could actually execute. I suspect that you tried to do something like echo an array item inside of a double-quote delimited string, e.g.:

    echo "Foo: $_POST['foo']";

    which should instead be written as:

    echo "Foo: $_POST[foo]";

    However, we'd have to see the code that the error message is referring to in order to say for sure if this is the case.

    funkymonkey;10983353 wrote:

    What is "T_ENCAPSED_AND_WHITESPACE"?
    What is "T_STRING or T_VARIABLE or T_NUM_STRING"

    Lexical analysis is used in programming languages to take the human-readable "script" or "code" that you've written and turn it into a series of symbols that the compiler/parser/whatever can understand and thus translate into executable instructions. These symbols are often called "tokens" (a specific type of lexical unit).

      $sql= "INSERT INTO `Client_Info` (Last_Name, First_Name, Middle_Name, Date_of_Birth, Street_Address, City, State, Zip_Code, Phone_Number, Email, Preferred_Contact, Gender, Sexual_Orientation, Race_Ethnicity, 
      Gender_Presentation, Body_Type, Height, Weight, Felony, Partners_Gender, Partners_Sexual_Orientation, 
      Partners_Race_Ethnicity, Partners_Gender_Presentation, Partners_Body_Type, Partners_Age, Partners_Height, Turn_On, Turn_Off, Celebrity_Crush, First_thing_you_notice, Deal_Breaker)
      VALUES ($_POST['lastname'],$_POST['firstname'],$_POST['middlename'],$_POST['birthdate'],
      $_POST['streetaddress'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['phone'],
      $_POST['email'],$_POST['contactmethod'],$_POST['yourgender'],$_POST['yourorientation'],
      $_POST['ethnicity'],$_POST['yourpresentation'],$_POST['bodytype'],$_POST['height'],
      $_POST['weight'],$_POST['felony'],'$partnersgender','$partnersorientation',
      '$partnerethnicity','$partnerspresentation','$partnerbodytype',
      '$partnersage',$_POST['partnersheight'],$_POST['turnon'],$_POST['turnoff'],
      $_POST['celebritycrush'],$_POST['firstthing'],$_POST['dealbreaker']);

      Here's the line that the error says is incorrect

      Partners_Race_Ethnicity, Partners_Gender_Presentation, Partners_Body_Type, Partners_Age, Partners_Height,

        Did you even read my post above?

        bradgrafelman;10983354 wrote:

        I suspect that you tried to do something like echo an array item inside of a double-quote delimited string, e.g.:

        echo "Foo: $_POST['foo']";

        which should instead be written as:

        echo "Foo: $_POST[foo]";

        However, also note that user-supplied data should never be placed directly into a SQL query string, else your code will be vulnerable to SQL injection attacks and/or just plain SQL errors. Instead, you must first sanitize the data with a function such as [man]mysql_real_escape_string/man (for string values) or use prepared statements.

          Thank you, your last post has helped eliminate several of my errors 🙂

          However, i am receiving another error: syntax error, unexpected T_STRING on line 59.

          $sql= "INSERT INTO `Emotional` 
          (It_is_difficult_for_me_to_let_people_get_emotionally_close_to_me, I_sometimes_find_it_difficult_to_trust_people, Try_not_to_dwell_on_an_issue_once_it_is_resolved, Show_that_my_partner_needs_are_important, The_friendship_between_me_and_my_partner, Being_able_to_make_compromises) 
          VALUES ('$_POST[longterm]','$_POST[difficulttrust]','$_POST[dwellonissue]','$_POST[partnerneeds]',
          '$_POST[friendshippartner]','$_POST[makecompromises]')";

          Can you help me out?

            There are no syntax errors in the code snippet you posted.

              Really? Well what should I do if the syntax error says its on a line but there are no errors on the line? Should I assume that there are errors elsewhere?

                funkymonkey;10983373 wrote:

                Really? Well what should I do if the syntax error says its on a line but there are no errors on the line? Should I assume that there are errors elsewhere?

                The error message relates to where php 'broke down' trying to read your code. It's not uncommon for the 'actual' location of the error to be some lines before.

                  If all else fails, post lines 1-60 so we can see all of the code before the supposedly erroneous line.

                    I've tried for the last for hours to go over everything to see what is wrong. No luck. I'm sorry that i have to post 60 lines of code here, and I am very appreciative of your help.

                    <?php
                      $con = mysql_connect("localhost","myaccount","mypassword");
                     if (!$con)
                       {
                       die('Could not connect: ' . mysql_error());
                       }
                    
                    mysql_select_db("mydatabase", $con);
                    
                    $arraybodytype = array($_POST['partnerbodytype']);
                    $parnterbodytype= implode(",",$arraybodytype);
                    $arrayethnicity = array($_POST['partnerethnicity']);
                    $partnerethnicity= implode(",",$arrayethnicity);
                    $arrayage= array($_POST['partnersage']);
                    $partnersage= implode(",",$arrayage);
                    $arraygender= array($_POST['partnersgender']);
                    $partnersgender= implode(",",$arraygender);
                    $arrayorientation= array($_POST['partnersorientation']);
                    $partnersorientation= implode(",",$arrayorientation);
                    $arraypresentation= array($_POST['partnerspresentation']);
                    $partnerspresentation= implode(",",$arraypresentation);
                    
                    $sql= "INSERT INTO `Client_Info` (Last_Name, First_Name, Middle_Name, Date_of_Birth, Street_Address, City, State, Zip_Code, Phone_Number, Email, Preferred_Contact, Gender, Sexual_Orientation, Race_Ethnicity, 
                    Gender_Presentation, Body_Type, Height, Weight, Felony, Partners_Gender, Partners_Sexual_Orientation, 
                    Partners_Race_Ethnicity, Partners_Gender_Presentation, Partners_Body_Type, Partners_Age, Partners_Height, Turn_On, Turn_Off, Celebrity_Crush, First_thing_you_notice, Deal_Breaker)
                    VALUES ('$_POST[lastname]','$_POST[firstname]','$_POST[middlename]','$_POST[birthdate]',
                    '$_POST[streetaddress]','$_POST[city],'$_POST[state]','$_POST[zip]','$_POST[phone]',
                    '$_POST[email]','$_POST[contactmethod]','$_POST[yourgender]','$_POST[yourorientation]',
                    '$_POST[ethnicity]','$_POST[yourpresentation]','$_POST[bodytype]','$_POST[height]',
                    '$_POST[weight]','$_POST[felony]','$partnersgender','$partnersorientation',
                    '$partnerethnicity','$partnerspresentation','$partnerbodytype',
                    '$partnersage','$_POST[partnersheight]','$_POST[turnon]','$_POST[turnoff]',
                    '$_POST[celebritycrush]','$_POST[firstthing]','$_POST[dealbreaker]')";
                    
                    $sql= "INSERT INTO `Lifestyles` (Employment, Occupation, Education_Achieved, Children, Pets, Drink, Smoke, Socializing, Achieving_your_goals_in_life, Working_career, Keeping_physically_fit, Maintaining_a_healthy_lifestyle, Making_new_riends, Dining_out, Traveling, Partners_level_of_education, Partners_Smoke, Partners_Drink, Partners_Employment, Partners_Religious_beliefs) 
                    VALUES ('$_POST[employed]','$_POST[occupation]','$_POST[educationlevel]','$_POST[yourchildren]',
                    '$_POST[yourpets]','$_POST[yourdrink]','$_POST[yoursmoke]','$_POST[socializing]',
                    '$_POST[achievinggoals]','$_POST[workingcareer]','$_POST[keepingfit]','$_POST[healthylifestyle]',
                    '$_POST[newfriends]','$_POST[diningout]','$_POST[traveling]','$_POST[partnerseducation]',
                    '$_POST[partnersmokes]','$_POST[partnerdrinks]','$_POST[partnersemployment]','$_POST[partnersfaith]')";
                    
                    $sql= "INSERT INTO `Values` (I_am_looking_for_a_long_term_relationship, A_serious_relationship_needs_to_be_exclusive_monogamous, Being_monogamous_helps_build_trust_and_intimacy, 
                    Being_monogamous_causes_relationships_to_get_boring_over_time) 
                    VALUES ('$_POST[longterm]','$_POST[seriousexclusive]','$_POST[monogamousintimacy]',
                    '$_POST[monogamousboring]')";
                    
                    $sql= "INSERT INTO `Emotional` 
                    (It_is_difficult_for_me_to_let_people_get_emotionally_close_to_me, I_sometimes_find_it_difficult_to_trust_people, Try_not_to_dwell_on_an_issue_once_it_is_resolved, Show_that_my_partner_needs_are_important, The_friendship_between_me_and_my_partner, Being_able_to_make_compromises) 
                    VALUES ('$_POST[longterm]','$_POST[difficulttrust]','$_POST[dwellonissue]','$_POST[partnerneeds]',
                    '$_POST[friendshippartner]','$_POST[makecompromises]')";

                      50 lines, no error, missing a few?

                        Here is it in its entirety.

                        <?php
                          $con = mysql_connect("localhost","myusername","mypassword");
                         if (!$con)
                           {
                           die('Could not connect: ' . mysql_error());
                           }
                        
                        mysql_select_db("mydatabase", $con);
                        
                        $arraybodytype = array($_POST['partnerbodytype']);
                        $parnterbodytype= implode(",",$arraybodytype);
                        $arrayethnicity = array($_POST['partnerethnicity']);
                        $partnerethnicity= implode(",",$arrayethnicity);
                        $arrayage= array($_POST['partnersage']);
                        $partnersage= implode(",",$arrayage);
                        $arraygender= array($_POST['partnersgender']);
                        $partnersgender= implode(",",$arraygender);
                        $arrayorientation= array($_POST['partnersorientation']);
                        $partnersorientation= implode(",",$arrayorientation);
                        $arraypresentation= array($_POST['partnerspresentation']);
                        $partnerspresentation= implode(",",$arraypresentation);
                        
                        $sql= "INSERT INTO `Client_Info` (Last_Name, First_Name, Middle_Name, Date_of_Birth, Street_Address, City, State, Zip_Code, Phone_Number, Email, Preferred_Contact, Gender, Sexual_Orientation, Race_Ethnicity, 
                        Gender_Presentation, Body_Type, Height, Weight, Felony, Partners_Gender, Partners_Sexual_Orientation, 
                        Partners_Race_Ethnicity, Partners_Gender_Presentation, Partners_Body_Type, Partners_Age, Partners_Height, Turn_On, Turn_Off, Celebrity_Crush, First_thing_you_notice, Deal_Breaker)
                        VALUES ('$_POST[lastname]','$_POST[firstname]','$_POST[middlename]','$_POST[birthdate]',
                        '$_POST[streetaddress]','$_POST[city],'$_POST[state]','$_POST[zip]','$_POST[phone]',
                        '$_POST[email]','$_POST[contactmethod]','$_POST[yourgender]','$_POST[yourorientation]',
                        '$_POST[ethnicity]','$_POST[yourpresentation]','$_POST[bodytype]','$_POST[height]',
                        '$_POST[weight]','$_POST[felony]','$partnersgender','$partnersorientation',
                        '$partnerethnicity','$partnerspresentation','$partnerbodytype',
                        '$partnersage','$_POST[partnersheight]','$_POST[turnon]','$_POST[turnoff]',
                        '$_POST[celebritycrush]','$_POST[firstthing]','$_POST[dealbreaker]')";
                        
                        $sql= "INSERT INTO `Lifestyles` (Employment, Occupation, Education_Achieved, Children, Pets, Drink, Smoke, Socializing, Achieving_your_goals_in_life, Working_career, Keeping_physically_fit, Maintaining_a_healthy_lifestyle, Making_new_riends, Dining_out, Traveling, Partners_level_of_education, Partners_Smoke, Partners_Drink, Partners_Employment, Partners_Religious_beliefs) 
                        VALUES ('$_POST[employed]','$_POST[occupation]','$_POST[educationlevel]','$_POST[yourchildren]',
                        '$_POST[yourpets]','$_POST[yourdrink]','$_POST[yoursmoke]','$_POST[socializing]',
                        '$_POST[achievinggoals]','$_POST[workingcareer]','$_POST[keepingfit]','$_POST[healthylifestyle]',
                        '$_POST[newfriends]','$_POST[diningout]','$_POST[traveling]','$_POST[partnerseducation]',
                        '$_POST[partnersmokes]','$_POST[partnerdrinks]','$_POST[partnersemployment]','$_POST[partnersfaith]')";
                        
                        $sql= "INSERT INTO `Values` (I_am_looking_for_a_long_term_relationship, A_serious_relationship_needs_to_be_exclusive_monogamous, Being_monogamous_helps_build_trust_and_intimacy, 
                        Being_monogamous_causes_relationships_to_get_boring_over_time) 
                        VALUES ('$_POST[longterm]','$_POST[seriousexclusive]','$_POST[monogamousintimacy]',
                        '$_POST[monogamousboring]')";
                        
                        $sql= "INSERT INTO `Emotional` 
                        (It_is_difficult_for_me_to_let_people_get_emotionally_close_to_me, I_sometimes_find_it_difficult_to_trust_people, Try_not_to_dwell_on_an_issue_once_it_is_resolved, Show_that_my_partner_needs_are_important, The_friendship_between_me_and_my_partner, Being_able_to_make_compromises) 
                        VALUES ('$_POST[longterm]','$_POST[difficulttrust]','$_POST[dwellonissue]','$_POST[partnerneeds]',
                        '$_POST[friendshippartner]','$_POST[makecompromises]')";
                        
                        $sql= "INSERT INTO `Communication` (When_I_get_romantically_involved_I_tell_my_partner_everything,  Try_to_accommodate_the_other_person's_position, Try_to_resolve_conflict_quickly, Being_able_to_discuss_with_my_parnter_how_I_am_feeling, Having_my_parnter_be_open_with_me_about_how_she/he_feels) 
                        VALUES ('$_POST[telleverything]','$_POST[accomodatepartner]','$_POST[resolveconflict]',
                        '$_POST[discussmyfeelings]')";
                        
                        $sql= INSERT INTO Romance (Engage_in_public_displays_of_affection, Provide_physical_intimacy_and_affection_to_my_partner, Public_displays_of_affection, Doing_special_things_to_let_my_parnter_know_how_important_he/she, Enjoying_physical_closeness_with_my_partner, Spending_quality_time_with_my_partner, 
                        Plan_the_date, Pay_for_dinner, Pick_up_your_date, Creating_romance_in_a_relationship, 
                        Sexual_Activity) 
                        VALUES ('$_POST[engagepda]','$_POST[physicalintimacy]',
                        '$_POST[importantpda]','$_POST[specialthings]','$_POST[physicalcloseness]',
                        '$_POST[qualitytime]','$_POST[planthedate]','$_POST[payfordinner]','$_POST[drivetodate]',
                        '$_POST[creatingromance]','$_POST[sexualactivity]')";
                        
                        $arraythreebest= array('$_POST[threeyoudobest]');
                        $arraythreeyoudobest= implode(",",$arraythreebest);
                        
                        $sql= "INSERT INTO Activity_Skills (Three_You_Do_Best) VALUES ('$arraythreeyoudobest')";
                        
                        $sql= "INSERT INTO Personality (EIQ1, EIQ2, EIQ3, EIQ4, EIQ5, SN1Q, SN2Q, SN3Q, SN4Q, SN5Q, 
                        TF1Q, TF2Q, TF3Q, TF4Q, TH5Q, JP1Q, JP2Q, JP3Q, JP4Q, JP5Q) VALUES ('$_POST[eiq1]',
                        '$_POST[eiq2]','$_POST[eiq3]','$_POST[eiq3]','$_POST[eiq4]','$_POST[eiq5]','$_POST[sn1q]',
                        '$_POST[sn2q]','$_POST[sn3q]','$_POST[sn4q]','$_POST[sn5q]','$_POST[jp1q]','$_POST[jp2q]',
                        '$_POST[jp3q]','$_POST[jp4q]','$_POST[jp5q]')";
                        
                        $sql= "INSERT INTO Interests (Making_art_and_culture_an_ongoing_part_of_my_life, Live_music, 
                        Movies, Listening_to_music, Watching_TV, Parties, Board_game, Art, Shopping, Friendship) 
                        VALUES ('$_POST[artandculture]','$_POST[livemusic]','$_POST[movies]','$_POST[listeningtomusic]',
                        '$_POST[watchingtv]','$_POST[reading]','$_POST[parties]','$_POST[boardgames]','$_POST[art]',
                        '$_POST[shopping]','$_POST[friendship]')";
                        
                        $arrayfriendsdescriptions= array('$_POST[friendsdescriptions]');
                        $friendsdescriptions= implode(",",$arrayfriendsdescriptions);
                        $arrayidealpartner= array('$_POST[idealpartner]');
                        $idealpartner= implode(",",$arrayidealpartner);
                        
                        
                        $sql= INSERT INTO Word_Descriptions (Worst_Day1, Worst_Day2, Worst_Day3, 
                        Friends_Description1, Ideal_Partner1) VALUES ('$_POST[worstday1]',
                        '$_POST[worstday2]','$_POST[worstday3]','$friendsdescriptions','$idealpartner')";
                        
                        if (!mysql_query($sql,$con))
                           {
                           die('Error: ' . mysql_error());
                           }
                         echo successful;
                        
                        exit();
                        mysql_close($con)
                        ?>
                        
                        

                          Notice any problems with the syntax highlighting here:

                          $sql= INSERT INTO Romance (Engage_in_public_displays_of_affection, Provide_physical_intimacy_and_affection_to_my_partner, Public_displays_of_affection, Doing_special_things_to_let_my_parnter_know_how_important_he/she, Enjoying_physical_closeness_with_my_partner, Spending_quality_time_with_my_partner,
                          Plan_the_date, Pay_for_dinner, Pick_up_your_date, Creating_romance_in_a_relationship, 
                          Sexual_Activity) 
                          VALUES ('$_POST[engagepda]','$_POST[physicalintimacy]', 
                          '$_POST[importantpda]','$_POST[specialthings]','$_POST[physicalcloseness]', 
                          '$_POST[qualitytime]','$_POST[planthedate]','$_POST[payfordinner]','$_POST[drivetodate]', 
                          '$_POST[creatingromance]','$_POST[sexualactivity]')"; 

                          ?

                          (Hint: What is the opening delimiter for that SQL query string?)

                            Write a Reply...