1

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...

3
  • The error message says the problem is on line 91. Which line of your code is that? Commented Aug 4, 2014 at 3:46
  • 1
    $s = mysql_query("select * from user_reg where mid='$mid'"); $f = mysql_fetch_array($s); <?php ... - is that your actual code? Plus, are there any spaces before your abc;? <= that is very important. Commented Aug 4, 2014 at 3:47
  • @Ghost - You removed the spaces before abc; in OP's code (in an edit), which stands to be one of the possible errors with OP's code. I did a rollback. Please be careful when editing code. This could have had an impact on my answer. Commented Aug 4, 2014 at 4:30

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

4 Comments

sorry about the revision yes that can cause major issues thanks for the heads up
@Ghost You're welcome and thanks. Had it not been a heredoc-related question, it would have been OK. cheers
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 <img> tag for displaying user's information.
@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.
0

try to use like this.

$s = mysql_query("select * from user_reg where mid='".trim($mid)."'");

1 Comment

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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.