Parse error: syntax error, unexpected T_VARIABLE
Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Thread: Parse error: syntax error, unexpected T_VARIABLE

  1. #1
    Junior Member
    Join Date
    Mar 2005
    Location
    Nyack, NY
    Posts
    3

    Parse error: syntax error, unexpected T_VARIABLE

    hi everyone,

    I'm getting this error message from my script
    "Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\Apache Group\Apache2\htdocs\sel_byid.php on line 18".
    I have no Idea what this is or more importantly what it is trying to tell me to fix. I just started working with PHP, MYSQL, and APACHE. Here is my script, and thank you for your help.

    PHP Code:
    <?
    $db_name 
    "testdb2";
    $table_name "my_music";

    $connection = @mysql_connect("localhost""xxxxx""xxxxx")
        or die(
    mysql_error());

    $db = @mysql_select_db($db_name$connection) or die(mysql_error());

    $sql "SELECT * FROM $table_name ORDER BY id";

    $result = @mysql_query($sql,$connection) or die(mysql_error());

    while (
    $row mysql_fetch_array($result)) {

    $id $row['id'];
    $format $row['format']
    $title stripslashes($row['title']);
    $artist_fn stripslashes($row['artist_fn']);
    $artist_ln stripslashes($row['artist_ln']);
    $rec_label stripslashes($row['rec_label']);
    $my_notes stripslashes($row['my_notes']);
    $date_acq $row['date_acq'];

    if (
    artist_fn != "") {
    $artist_fullname trim("$artist_fn $artist_ln");
    } else {
        
    $artist_fullname trim("artist_ln");
    }

    if (
    $date_acq == "0000-00-00") {
        
    $date_acq "[unknown]";
    }

    $display_block .= "<P><strong>$title</strong> on $rec_label,
        by 
    $artist_fullname<br>
    $my_notes <em>(acquired:$date_acq, format:$format)</em></P>";
    }
    ?>

    <HTML>
    <HEAD>
    <TITLE>My Music (Ordered by ID)</TITLE>
    </HEAD>
    <BODY>
    <H1>My Music: Ordered By ID</H1>
    <? echo "$display_block"?>
    <P><a href="my_menu.html">Return to menu</a></P>
    </BODY>
    </HTML>
    Last edited by bradgrafelman; 08-02-2010 at 05:02 PM. Reason: PHP bbcode tags added

  2. #2
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,569
    $format = $row['format']
    is missing the terminating semi-colon.

    Basically, look at line 18, and the surrounding code if necessary, to determine the problem.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    1
    I have similar problem. I see the message: "Parse error: syntax error, unexpected T_VARIABLE in ......\moviedata.php on line 16" when I open my file and I can't understend where is my mistake. Here is my code:
    <?php
    //connect to MySQL
    $connect = mysql_connect("localhost", "xxx", "xxx") or die ("Proveri si vryzkata sys server-a.");

    //uverqvame se 4e polzame pravilnata DB
    mysql_select_db("moviesite");

    //vyvejdane da danni v tablicata "movie"
    $insert = "INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) " .
    "VALUES (1, 'Bruce Almighty', 5, 2003, 1, 2), " .
    "(2, 'Office Space', 5, 1999, 5, 6), " .
    "(3, 'Grand Canyon', 2, 1991, 4, 3)";
    $results = mysql_query($insert)

    //vyvejdane na danni v tablicata "movietype"
    $type = "INSERT INTO movietype (movietype_id, movietype_label) " .
    "VALUES (1, 'Sci Fi'), " .
    "(2, 'Drama'), " .
    "(3, 'Adventure'), " .
    "(4, 'War'), " .
    "(5, 'Comedy'), " .
    "(6, 'Horror'), " .
    "(7, 'Action'), " .
    "(8, 'Kids')" ;
    $resuts = mysql_query($type) or die (mysql_error());

    //vyvejdane na danni v tablicata "people"
    $people = "INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) " .
    "VALUES (1, 'Jim Carrey', 1, 0), " .
    "(2, 'Tom Shadyac', 0, 1), " .
    "(3, 'Lawrence Kasdan', 0, 1), " .
    "(4, 'Kevin Kline', 1, 0), " .
    "(5, 'Ron Livingston', 1, 0), " .
    "(6, 'Mike Judje', 0, 1)";
    $results = mysql_query($people) or die (mysql_error());

    echo "Data inserted successfully!";
    ?>
    Last edited by Djibri; 04-05-2007 at 03:57 PM.

  4. #4
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,569
    Djibri, you are missing a terminating semi-colon on line 13:
    PHP Code:
    $results mysql_query($insert
    Next time kindly start your own thread instead of resurrecting an old thread, especially one that is not yours. Link to the old thread if you must.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Also, when posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.

  6. #6
    Member
    Join Date
    Aug 2008
    Posts
    29
    Hi All,

    This is racking my brain. I am getting the all infamous "Parse error: syntax error, unexpected T_VARIABLE" message. I know that 9 times out of 10 your either missing a semi-colon or opening/closing brackets in statements. I have checked my code like 20 times and I am just not seeing it! :P

    Maybe you guys could see it.

    I am trying to take this "test" I guess you can call it for this freelance php developer gig, and want to make sure all the code works before I send it back to them for review.

    Exact error is: "
    Parse error: syntax error, unexpected T_VARIABLE in /home/content/j/m/b/jmbrink26/html/testing/index.php on line 39"

    Here is the code:
    PHP Code:
    <?php

    //Database Connection
    $msdb mysql_connect("xxx""xxx""xxx");
    mysql_select_db("test"$msdb) or die(mysql_error());

    /*
    GENERAL INFORMATION:
        Below is the current table structure for 'members':
    =====
    ID: id (autoincrement)
    firstname
    lastname
    phonenumber
    =====

    PUT YOUR NAME HERE PLEASE: John Doe

    PART 1:
    -------
        * Below, write the PHP code to insert a first name, last name, and phone number
    into the 'members' table.  Use an HTML form to collect this information, then store it to the 'members' table.
    // 
    */


    /*
    PART 2:
    -------
        * Below, write the PHP code to retrieve the previously inserted record from the
    'tests' table and display it in the browser.
    //*/

    // PHP Code
    // Code to pass HTML POST data

    $firstName $_POST['firstname'];
    $lastName $_POST['lastname'];
    $phoneNumber $_POST['phonenumber']; //This is line 39 in my IDE
    if(!$firstName || !$lastName || !$phoneNumber) {
      echo 
    "You did not enter all the necessary data into the fields as requested. Please fill in the information below and try again. Thank you.";
      } else {
      
    $number is_numeric($phoneNumber);
      if(
    $number == false) {
        echo 
    "You did not type the Phone Number in the format shown as example in the field. Please fill in the information below and try again. Thank you.";
        } else {
          
    $insert "INSERT INTO members (firstname, lastname, phonenumber) VALUES($firstName$lastName$phoneNumber);";
          
    mysql_query($insert);
          
    //Code to retrieve record just inserted
          
    $query "SELECT * FROM members WHERE firstname = $firstName AND lastname = $lastName AND phonenumber = $phoneNumber;";
          
    $result mysql_query($query);
          echo 
    $result;
          }
    ?>

    <html>
      
      <head>
      
          <title>PHP TEST</title>
        <!-- Link to a fake CSS Stylesheet -->
        <link rel="stylesheet" href="test.css" />
      </head>
      
      <body>
      
          <h2>PHP TEST</h2>
        <br />
        <p>Please enter data into all the fields, or an error will display. Thank you for your cooperation.</p>
        <br />
        <table name="form_table" id="form_table">
          <form name="phptest_form" id="phptest_form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
            <tr>
              <td>First Name &nbsp;</td>
              <td><input type="text" name="firstname" id="firstname" /></td>
            </tr>
            <tr>
              <td>Last Name &nbsp;</td>
              <td><input type="text" name="lastname" id="lastname" /></td>
            </tr>
            <tr>
              <td>Phone Number &nbsp;</td>
              <td><input type="text" name="phonenumber" id="phonenumber" value="0000000000" /></td>
            </tr>
            <tr>
              <td></td>
              <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
            </tr>
          </form>
        </table>
      </body>
    </html>
    Thanks in advance for your help.
    Last edited by bradgrafelman; 08-15-2008 at 02:58 AM.

  7. #7
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Is that the entire script? I get a different parse error: Parse error: syntax error, unexpected $end in C:\php\test.php on line 92.

    That parse error is referring to the unclosed '}' on the first else statement.

  8. #8
    Bug Killer
    Join Date
    Jun 2008
    Location
    Wisconsin
    Posts
    665
    Quote Originally Posted by laserlight View Post
    Next time kindly start your own thread instead of resurrecting an old thread, especially one that is not yours. Link to the old thread if you must.
    Next time maybe a bit of reading would be in order (2 posts above yours)

    But the solution is maybe a bit easier than you think.

    I have had comment lines throw off the error reporting, as far as the line with the error goes. Count the number of commented lines and add that to the 39 and see if you find the problem. If there are more commented lines in the code as you add you may need to add one more line for each. This will get you closer to the correct line of the error.

  9. #9
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Also, jmbrink26, this bit of code:
    PHP Code:
    <?php $_SERVER['PHP_SELF']; ?>
    does nothing. Perhaps you meant:
    PHP Code:
    <?php echo $_SERVER['PHP_SELF']; ?>
    ?

  10. #10
    Member
    Join Date
    Aug 2008
    Posts
    29
    Yes, that's it.

    Interestingly enough though, I copied all the text from the original file, and pasted it into a new file, and then I got that same error about the $end. I forgot 1 curley brace at the end, and that fixed that issue.

    Thanks for the reminder to put the echo in the php_self line, I totally forgot about that. Been a while since I've passed variables that way... That would explain why nothing ever gets inserted into the mysql table :P

    Thanks again. Much appreciated!

  11. #11
    Junior Member
    Join Date
    Oct 2008
    Posts
    5

    Exclamation Parse error: syntax error, unexpected T_VARIABLE

    hi every body
    i have a problem with this code:
    PHP Code:
    ////////////////////////////
    //       config.php       //
    ////////////////////////////


    ////////////////////////////////////// CONNECTIN TO DATABASE AND SELECTING IT
    <?php

    $host 
    $_POST['haddress'];
    $usser $_POST['huser'];
    $pass $_POST['hpass'];
    $db =   $_POST['hname'];
    $connect mysql_connect($host,$usser,$pass) or die('tghrg');
    mysql_select_db($connection,$db) or die('gggg');
        
    //////////////////////////////////// CREATING TABLES AND INSERTING MAIN DATA INTO THEM 
    //////////dedws
    $createinfo "create table pscms_maininfo (
    title     char(200)    not null default 'Simple cms by parsscript',
    sdir      char(255)    ,
    author    char(255)    not null  default 'parsscript.ir',
    about     text 
     )"
    ;

    sql_query($createinfo) or die('g')

    //////////////// sending grabed data into pscms_maininfo table

    $title = ($_POST['title']);
    $sdir $_post['sdir'];
    $author $_post['author'];
    $about $_post['about'];

    $sinfo "insert into pscms_maininfo (title,sdir,author,about)
           values ('
    $title','$sdir','$author','$about')";
    mysql_query($sinfo) or die ('اطلاعات بصورت صحیح ارسال نشدند')

    //////////////// creating table pscms_admin

    $adminc "create table pscms_admin (
    username    char(200) not null  default 'admin',
    password    char(200) not null  default 'admin'
    )"
    ;

    mysql_query($adminc) or die ('در ایجاد فضا برای ذخیره اطلاعات مدیریت اشکال وجود دارد ')
    //////////////// sending grabed data into pscms_admin table

    $username $_post['auser'];
    $password $_post['apass'];

    $sadmin "insert into pscms_admin (username,password)
                values ('
    $username','$password')";
    mysql_query($sadmin) or die ('ارسال اطلاعات مدیریت انجام نشد')

    //////////////// creating  table pscms_posts

    $cposts "create table pscms_posts (
    title  char(255),
    text   text   not null  default 'بدون محتوی'
    )"
    ;

    mysql_query($cposts) or die ('محلی برای ذخیره مطالب ایجاد نشد')
    //////////////// 


    <table border="0" width="50%" align="center">
        <
    tr>
            <
    td bgcolor="#004A18">
            <
    p align="center" dir="rtl">
            <
    font face="Tahoma" size="2" color="#E6FFE6">&#1587;یستم با موفقیت نصب گردید<span lang="en-us">!</span></font></td>
        
    </tr>
        <
    tr>
            <
    td bgcolor="#6F4200">
            <
    p dir="rtl"><font face="Tahoma" size="2" color="#FFAB2D">&#1740;کی را انتخاب کنید :</font></p>
            
    <p dir="rtl" align="center"><font face="Tahoma" size="2">
            <
    font color="#FFAB2D">&nbsp;</font><a href="index.php"><font color="#FFAB2D">&#1589;فحه اصلی وبسایت</font></a><font color="#FFAB2D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            
    </font>
    <
    a href="admin/index.php"><font color="#FFAB2D">&#1605;رکز کنترل وبسایت 
            
    </font> </a>
            </
    font>
    </
    td>
        </
    tr>
    </
    table>

    i have a form wich it action is the page contain the this code
    when i execute the form i get this error

    Parse error: syntax error, unexpected T_VARIABLE in D:\Downloads\xampplite\htdocs\b\config.php on line 29



    what should i do??????
    Last edited by bradgrafelman; 08-02-2010 at 05:03 PM. Reason: PHP bbcode tags added

  12. #12
    Senior Member djjjozsi's Avatar
    Join Date
    Oct 2008
    Location
    Hungary
    Posts
    2,038
    you must use ; signs at that lines end that must close the commands:

    and you forget to close your PHP block
    ?> was misssing
    AND $_POST is with CAPITAL letters!

    And, check if you wrote mysql_query command... i found 1 part where you wrote it as wrong..

    and use the source code insert in this forum.


    PHP Code:
    <?php

    $host 
    $_POST['haddress'];
    $usser $_POST['huser'];
    $pass $_POST['hpass'];
    $db $_POST['hname'];
    $connect mysql_connect($host,$usser,$pass) or die('tghrg');
    mysql_select_db($connection,$db) or die('gggg');

    //////////////////////////////////// CREATING TABLES AND INSERTING MAIN DATA INTO THEM
    //////////dedws
    $createinfo "create table pscms_maininfo (
    title char(200) not null default 'Simple cms by parsscript',
    sdir char(255) ,
    author char(255) not null default 'parsscript.ir',
    about text
    )"
    ;

    mysql_query($createinfo) or die('g');

    //////////////// sending grabed data into pscms_maininfo table

    $title $_POST['title'];
    $sdir $_POST['sdir'];
    $author $_POST['author'];
    $about $_POST['about'];

    $sinfo "insert into pscms_maininfo (title,sdir,author,about)
    values ('
    $title','$sdir','$author','$about')";
    mysql_query($sinfo) or die ('اطلاعات بصورت صحیح ارسال نشدند');

    //////////////// creating table pscms_admin

    $adminc "create table pscms_admin (
    username char(200) not null default 'admin',
    password char(200) not null default 'admin'
    )"
    ;

    mysql_query($adminc) or die ('در ایجاد فضا برای ذخیره اطلاعات مدیریت اشکال وجود دارد ');
    //////////////// sending grabed data into pscms_admin table

    $username $_POST['auser'];
    $password $_POST['apass'];

    $sadmin "insert into pscms_admin (username,password) values ('$username','$password')";
    mysql_query($sadmin) or die ('ارسال اطلاعات مدیریت انجام نشد');

    //////////////// creating table pscms_posts

    $cposts "create table pscms_posts (
    title char(255),
    text text not null default 'بدون محتوی'
    )"
    ;

    mysql_query($cposts) or die ('محلی برای ذخیره مطالب ایجاد نشد');

    ?>

    <table border="0" width="50%" align="center">
    <tr>
    <td bgcolor="#004A18">
    <p align="center" dir="rtl">
    <font face="Tahoma" size="2" color="#E6FFE6">سیستم با موفقیت نصب گردید<span lang="en-us">!</span></font></td>
    </tr>
    <tr>
    <td bgcolor="#6F4200">
    <p dir="rtl"><font face="Tahoma" size="2" color="#FFAB2D">یکی را انتخاب کنید :</font></p>
    <p dir="rtl" align="center"><font face="Tahoma" size="2">
    <font color="#FFAB2D">&nbsp;</font><a href="index.php"><font color="#FFAB2D">صفحه اصلی وبسایت</font></a><font color="#FFAB2D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <a href="admin/index.php"><font color="#FFAB2D">مرکز کنترل وبسایت
    </font> </a>
    </font>
    </td>
    </tr>
    </table>

  13. #13
    Junior Member
    Join Date
    Oct 2008
    Posts
    5

    Exclamation

    Quote Originally Posted by djjjozsi View Post
    you must use ; signs at that lines end that must close the commands:

    and you forget to close your PHP block
    ?> was misssing
    AND $_POST is with CAPITAL letters!

    And, check if you wrote mysql_query command... i found 1 part where you wrote it as wrong..

    and use the source code insert in this forum.


    PHP Code:
    <?php

    $host 
    $_POST['haddress'];
    $usser $_POST['huser'];
    $pass $_POST['hpass'];
    $db $_POST['hname'];
    $connect mysql_connect($host,$usser,$pass) or die('tghrg');
    mysql_select_db($connection,$db) or die('gggg');

    //////////////////////////////////// CREATING TABLES AND INSERTING MAIN DATA INTO THEM
    //////////dedws
    $createinfo "create table pscms_maininfo (
    title char(200) not null default 'Simple cms by parsscript',
    sdir char(255) ,
    author char(255) not null default 'parsscript.ir',
    about text
    )"
    ;

    mysql_query($createinfo) or die('g');

    //////////////// sending grabed data into pscms_maininfo table

    $title $_POST['title'];
    $sdir $_POST['sdir'];
    $author $_POST['author'];
    $about $_POST['about'];

    $sinfo "insert into pscms_maininfo (title,sdir,author,about)
    values ('
    $title','$sdir','$author','$about')";
    mysql_query($sinfo) or die ('اطلاعات بصورت صحیح ارسال نشدند');

    //////////////// creating table pscms_admin

    $adminc "create table pscms_admin (
    username char(200) not null default 'admin',
    password char(200) not null default 'admin'
    )"
    ;

    mysql_query($adminc) or die ('در ایجاد فضا برای ذخیره اطلاعات مدیریت اشکال وجود دارد ');
    //////////////// sending grabed data into pscms_admin table

    $username $_POST['auser'];
    $password $_POST['apass'];

    $sadmin "insert into pscms_admin (username,password) values ('$username','$password')";
    mysql_query($sadmin) or die ('ارسال اطلاعات مدیریت انجام نشد');

    //////////////// creating table pscms_posts

    $cposts "create table pscms_posts (
    title char(255),
    text text not null default 'بدون محتوی'
    )"
    ;

    mysql_query($cposts) or die ('محلی برای ذخیره مطالب ایجاد نشد');

    ?>

    <table border="0" width="50%" align="center">
    <tr>
    <td bgcolor="#004A18">
    <p align="center" dir="rtl">
    <font face="Tahoma" size="2" color="#E6FFE6">سیستم با موفقیت نصب گردید<span lang="en-us">!</span></font></td>
    </tr>
    <tr>
    <td bgcolor="#6F4200">
    <p dir="rtl"><font face="Tahoma" size="2" color="#FFAB2D">یکی را انتخاب کنید :</font></p>
    <p dir="rtl" align="center"><font face="Tahoma" size="2">
    <font color="#FFAB2D">&nbsp;</font><a href="index.php"><font color="#FFAB2D">صفحه اصلی وبسایت</font></a><font color="#FFAB2D">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </font>
    <a href="admin/index.php"><font color="#FFAB2D">مرکز کنترل وبسایت
    </font> </a>
    </font>
    </td>
    </tr>
    </table>
    thank you for answering
    i did what you told and i corrected the misings
    but still i have a problem when i execute the form i told you about this error coms
    Code:
    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Downloads\xampplite\htdocs\b\config.php on line 7
    tghrg
    now?

  14. #14
    Senior Member djjjozsi's Avatar
    Join Date
    Oct 2008
    Location
    Hungary
    Posts
    2,038
    Quote Originally Posted by hosseind600 View Post
    please answer my question...
    if you can
    i need your professional guides , please
    Lets write the values for the connection:

    $host = $_POST['haddress'];
    $usser = $_POST['huser'];
    $pass = $_POST['hpass'];
    $db = $_POST['hname'];

    $host = "*******";
    $usser ="*******";
    $pass = "*******";
    $db = "*******";

  15. #15
    Junior Member
    Join Date
    Oct 2008
    Posts
    5

    Exclamation again ... again

    again thank you

    this time this error comes
    Code:
    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\Downloads\xampplite\htdocs\b\config.php on line 8
    gggg
    do you know why?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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