Faustinodarnellmarissa's Profile

210
Points

Questions
40

Answers
54

  • Asked on July 15, 2020 in HTML.

    Parse error: syntax error, unexpected T_VARIABLE

    Possible scenario

    I can’t seem to find where my code has gone wrong. Here is my full error:

    Parse error: syntax error, unexpected T_VARIABLE on line x

    What I am trying

    $sql = 'SELECT * FROM dealer WHERE id="'$id.'"'; 

    Answer

    Parse error: A problem with the syntax of your program, such as leaving a semicolon off of the end of a statement or, like the case above, missing the . operator. The interpreter stops running your program when it encounters a parse error.

    In simple words this is a syntax error, meaning that there is something in your code stopping it from being parsed correctly and therefore running.

    What you should do is check carefully at the lines around where the error is for any simple mistakes.

    That error message means that in line x of the file, the PHP interpreter was expecting to see an open parenthesis but instead, it encountered something called T_VARIABLE. That T_VARIABLE thing is called a token. It’s the PHP interpreter’s way of expressing different fundamental parts of programs. When the interpreter reads in a program, it translates what you’ve written into a list of tokens. Wherever you put a variable in your program, there is aT_VARIABLE token in the interpreter’s list.

    Good read: List of Parser Tokens

    So make sure you enable at least E_PARSE in your php.ini. Parse errors should not exist in production scripts.

    I always recommended to add the following statement, while coding:

    error_reporting(E_ALL); 

    PHP error reporting

    Also, a good idea to use an IDE which will let you know parse errors while typing. You can use:

    1. NetBeans (a fine piece of beauty, free software) (the best in my opinion)
    2. PhpStorm (uncle Gordon love this: P, paid plan, contains proprietary and free software)
    3. Eclipse (beauty and the beast, free software)

    Related Questions:

    • 1003 views
    • 30 answers
    • 0 votes

  • Here are some approaches to work with asynchronous requests:

    1. Browser Promise object
    2. Q – A promise library for JavaScript
    3. A+ Promises.js
    4. jQuery deferred
    5. XMLHttpRequest API
    6. Using callback concept – As implementation in first answer

    Example: jQuery deferred implementation to work with multiple requests

    var App = App || {};  App = {     getDataFromServer: function(){        var self = this,                  deferred = $.Deferred(),                  requests = [];        requests.push($.getJSON('request/ajax/url/1'));       requests.push($.getJSON('request/ajax/url/2'));        $.when.apply(jQuery, requests).done(function(xhrResponse) {         return deferred.resolve(xhrResponse.result);       });       return deferred;     },      init: function(){          this.getDataFromServer().done(_.bind(function(resp1, resp2) {             // Do the operations which you wanted to do when you            // get a response from Ajax, for example, log response.         }, this));     } }; App.init();

    • 943 views
    • 30 answers
    • 0 votes
  • From docs regarding update_or_create

    The update_or_create method tries to fetch an object from database based on the given kwargs. If a match is found, it updates the fields passed in the defaults dictionary.


    obj, created = Person.objects.update_or_create(     first_name='John', last_name='Lennon',     defaults={'first_name': 'Bob'}, ) 

    You should edit your defaults accordingly

    • 370 views
    • 1 answers
    • 0 votes
  • Asked on July 15, 2020 in Java.

    Try to remove the extends Movie from the MovieTestDrive class

    • 281 views
    • 2 answers
    • 0 votes