473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRIN

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
1 3669
Atli
5,058 Expert 4TB
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

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

Similar topics

5
by: Anna MZ | last post by:
I am new to php and have written the following mysql code to enter the details of a new user in the admin subdomain of my website: $sql = "INSERT INTO 'users' ('userid', 'username', 'upassword')...
1
epots9
by: epots9 | last post by:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/xxx.php on line xxx I get that message when i try to run my...
1
by: Phaelle | last post by:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' What does that error mean? I canīt find the mistake!! In another script, I have got another kind of mistake : parse...
3
by: basswhizz | last post by:
Hi everyone im a high school student and I'm having trouble with one of my projects could you please help!! I'm getting this error message. Parse error: syntax error, unexpected...
36
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
3
crystal2005
by: crystal2005 | last post by:
I found such eror message when i tried to test sending email. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in...
2
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
68
mideastgirl
by: mideastgirl | last post by:
I keep getting this error and I cannot figure it out. My curly brackets are closed, and I am using the correct tags for <?php to open and ?> to close my code. Can someone please help me! Here is...
2
by: TanjaPetro | last post by:
Hello to everyone. I changed a few files on my site and when I tried to log into the admin area I got this message: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting...
1
by: karine | last post by:
Hi, I keep getting this error message "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /home/env49986/public_html/welcome.php on line 16" below is the code ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.