0

I have been working on a PHP project, and i am getting an error in one file i.e

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\simple\directory.php on line 91

My code is:

$s = mysql_query("select * from user_reg where mid='$mid'");
$f = mysql_fetch_array($s);
<?php
    while($f = mysql_fetch_array($s))
    { echo "
    <div class='divtable'>
    <table border='0' cellspacing='10px'>
    <tr><td rowspan='4' align='center'><img src='user/$imgsrc' alt='$name' height='100px' width='100px' border='0' title=$name' /></td><th>Name</th><td><?php echo $f['name'];?></td></tr>
    <tr><th>Specialized In</th><td><?php echo $f['spl'];?></td></tr>
    <tr><th>Degrees</th><td><?php echo $f['de'];?></td></tr>
    </table>
    </div>";
    }
?>

Here i am retrieving the source of image from MySql Database.. I had also tried to overcome this problem by using heredoc syntax..

<?php
    while($f = mysql_fetch_array($s))
    { echo <<<abc
    <div class='divtable'>
    <table border='0' cellspacing='10px'>
    <tr><td rowspan='4' align='center'><img src='user/$imgsrc' alt='$name' height='100px' width='100px' border='0' title=$name' /></td><th>Name</th><td>$f['name']</td></tr>
    <tr><th>Specialized In</th><td>$f['spl']</td></tr>
    <tr><th>Degrees</th><td>$f['de']</td></tr>
    </table>
    </div>";
    abc;
    }
?>

But the error is same as the above.. Kindly help me in resolving this issue

I am using this while loop to display my user's details including photograph in my website, is there any loop same as while to do my work.

Thanks in Advance...

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Mak
  • 11

2 Answers2

2

EDIT:

An (code) edit was done by removing the spaces before abc; that should not have been approved.

A rollback was done, since this could have been a possible contributing error.


The (parse) error is caused by the single quotes inside $f['name'] and all others using the $f variables fetching the rows from DB, remove the quotes $f[name] and do the same for the others.

Plus, this abc; before your </div>";

There should not be anything before and/or after that. It looks as if you have 4 spaces before it.

    </div>";
    abc;
^^^^

Remove all the spaces before it, if there is indeed 4 spaces before abc; in your code.

Heredoc says:

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables.


Plus, there doesn't seem to contain any spaces following echo <<<abc however, keep in mind that there should not be anything following the identifier; this being and following abc in your case.

In doing so, will produce the following error:

Parse error: syntax error, unexpected '<<' (T_SL) in...(path to file on line x)

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • sorry about the revision yes that can cause major issues thanks for the heads up – Kevin Aug 04 '14 at 04:53
  • @Ghost You're welcome and thanks. Had it not been a [`heredoc-related`](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) question, it would have been OK. cheers – Funk Forty Niner Aug 04 '14 at 04:55
  • I had tried it by removing spaces before and after heredoc syntax, but I getting the same error again.... Actually my moto is to print all my user's image in one page by retrieving the source of the image from database. Right Now i am doing it by taking an tag for displaying user's information. – Mak Aug 04 '14 at 18:30
  • @user3739755 Did you also take care of `$f['name']` to `$f[name]` while doing the same for all the others? I've tested this having the same errors from start to finish. – Funk Forty Niner Aug 04 '14 at 19:23
0

try to use like this.

$s = mysql_query("select * from user_reg where mid='".trim($mid)."'");
Ricky
  • 284
  • 1
  • 3
  • 19
  • Hiya, this may well solve the problem - but you should know there are heaps of newbies on Stack Overflow, and they could learn a thing or two from your expertise. A little bit of explanation is always good. Don't forget that what may be obvious to you might not be so to them. :) – Taryn East Aug 04 '14 at 04:57