By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 3,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRIN

P: 7
Hi,
Kindly sort me out on this nagging issue, Unexpecting T_ENCAPSED_AND_WHITESPACE, expecting T_string or T_variable or T_NUM_STRING.
HERE IS THE CODE:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. class mainSport {
  4.   var $host;
  5.   var $username;
  6.   var $password;
  7.   var $table;
  8.  
  9.       public function display_public() {
  10.           $q = "SELECT * FROM sportsDB ORDER BY created DESC LIMIT 3";
  11.         $r = mysql_query($q);
  12.  
  13.             if ( $r !== false && mysql_num_rows($r) > 0 ) {
  14.                   while ( $a = mysql_fetch_assoc($r) ) {
  15.                     $title = stripslashes($a['title']);
  16.                     $bodytext = stripslashes($a['bodytext']);
  17.  
  18.                     $entry_display .= <<<ENTRY_DISPLAY
  19.  
  20.                     <h2>$title</h2>
  21.                     <p>
  22.                       $bodytext
  23.                         </p>
  24.  
  25.                     ENTRY_DISPLAY;
  26.                   }
  27.         } else {
  28.               $entry_display = <<<ENTRY_DISPLAY
  29.  
  30.             <h2>This Page Is Under Construction</h2>
  31.             <p>
  32.               No entries have been made on this page.
  33.               Please check back soon, or click the
  34.               link below to add an entry!
  35.             </p>
  36.  
  37.             ENTRY_DISPLAY;
  38.         }
  39.         $entry_display .= <<<ADMIN_OPTION
  40.  
  41.         <p class="admin_link">
  42.           <a href="{$_SERVER['PHP_SELF']}?admin=1">Add a New Entry</a>
  43.         </p>
  44.  
  45.         ADMIN_OPTION;
  46.  
  47.             return $entry_display;
  48.  
  49.   }
  50.  
  51.   public function display_admin() {
  52.     return <<<ADMIN_FORM
  53.  
  54.     <form action="{$_SERVER['PHP_SELF']}" method="post">
  55.       <label for="title">Title:</label>
  56.       <input name="title" id="title" type="text" maxlength="150" />
  57.       <label for="bodytext">Body Text:</label>
  58.       <textarea name="bodytext" id="bodytext"></textarea>
  59.       <input type="submit" value="Create This Entry!" />
  60.     </form>
  61.  
  62.     ADMIN_FORM;
  63.  
  64.       }
  65.  
  66.   public function write() {
  67.       if ( $p['title'] )
  68.           $title = mysql_real_escape_string($p['title']);
  69.     if ( $p['bodytext'])
  70.           $bodytext = mysql_real_escape_string($p['bodytext']);
  71.     if ( $title && $bodytext ) {
  72.           $created = time();
  73.           $sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')";
  74.           return mysql_query($sql);
  75.     } else {
  76.       return false;
  77.     }
  78.  
  79.   }
  80.  
  81.   public function connect() {
  82.           mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
  83.         mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
  84.  
  85.         return $this->buildDB();
  86.   }
  87.  
  88.   private function buildDB() {
  89.       $sql = <<<MySQL_QUERY
  90.         CREATE TABLE IF NOT EXISTS sportsDB (
  91.             title       VARCHAR(150),
  92.             bodytext    TEXT,
  93.             created     VARCHAR(100)
  94.         )
  95.         MySQL_QUERY;
  96.  
  97.         return mysql_query($sql);
  98.  
  99.     }
  100. }
  101. ?>
Mar 22 '11 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hey.

The problem is that you are using the heredoc syntax incorrectly. Check out the Heredoc syntax part in the manual.

Basically, the end delimiter must be the first thing in the line. If there is so much as a white-space before it, you will get a syntax error.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     // Will NOT work
  3.     $var = <<<HEREDOC
  4.  
  5.     HEREDOC;
  6.  
  7.     // Will work
  8.     $var = <<<HEREDOC
  9.  
  10. HEREDOC;
  11. ?>
  12.  
Mar 22 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.