syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
PHP Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
used
echo img src=$row['logo']>."<br />";
what is the correct use
I wanted to show it as a picture

You have to change your code as below:
echo "<img src='$row[logo]' /><br />";
OR
echo "<img src='".$row[logo]."' /><br />";

<?php
echo "some string {$variable['withKey']}";
encapsulate the variable with { and }

echo "<img src=\"$row['logo']\" />";
notice the quotes around your src attribute which are needed for your HTML to work

Related

How can I echo it properly? HTML+PHP issue [duplicate]

This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 3 years ago.
I have a problem with this line,is there any solution for a line which must contain both single and double quotation marks?
echo "<a href='/ad/.$row['id_ad']'>".$row['title'];
I get this error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Exit the "echo" and concatenate with a dot.
echo "<a href='/ad/" . $row['id_ad'] . "'>" . $row['title'];
That would be the exact match of your line but I believe you forgot to close the anchor.
echo "<a href='/ad/" . $row['id_ad'] . "'>" . $row['title'] . "</a>";

Not able to solve Parse Error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am writing php code in an html. Now I get a parse error which I am not able to trace!Could somebody help me fix it
echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'">
<img src="echo base_url('uploads/files/'.$file['file_name'])">
<p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
Error:-Parse error: syntax error, unexpected 'uploads' (T_STRING), expecting ',' or ';'
echo '<a href="'.base_url('uploads/files/'.$file['file_name']).'">
<img src="'.base_url('uploads/files/'.$file['file_name']).'">
<p>Uploaded On '.date("j M Y",strtotime($file['created'])).'</p>';
Step by step
$bu = base_url('uploads/files/'.$file['file_name']);
$d = date("j M Y",strtotime($file['created']));
echo '<img src="'.$bu.'"/><p>Uploaded On '.$d.'</p>';
to prevent typos and syntax errors
Note: added an missing </a>
Make a var like this :
$linkToImg = base_url('uploads/files/'.$file['file_name']);
$uploadDate = date('j M Y',strtotime($file['created']));
echo "<a href='". $linkToImg ."'>";
echo "<img src='". $linkToImg ."'>";
echo "<p>Uploaded On ". $uploadDate ."</p>";
echo "</a>"; // Don't forget to close <a> tag

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate]

This question already has an answer here:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate]
(1 answer)
Closed 6 years ago.
This is my code.
<?php
$name = 'John Doe';
echo 'My name is $name';
echo "I am from $_COOKIE['mylocation']";
i got an error from this
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in : eval()'d code on line 3
if any one know about this please help me.
The variables should not be enclosed in the quotes..It should be concatenated using . after closing the quotes
Close the single quotes in echo before $name as well as $_COOKIE['mylocation']
<?php
$name = 'John Doe';
echo 'My name is'.$name;
echo "I am from". $_COOKIE['mylocation'];
Remove the ':
<?php
$name = 'John Doe';
echo 'My name is $name';
echo "I am from $_COOKIE[mylocation]";
Beware of XSS vulnerability!

Error: Parse error: syntax error, unexpected '[', expecting ',' or ';' [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm getting a parse error:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in index.php on line 23
Line 23 is this:
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;
I changed the syntax in all similar lines to
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];
but I get the identical error message.
$er is an array of email messages. Each array element is an array of key-value pairs, and the value for the key 'header' is a long array of key-value pairs.
The function $er->GetMessage($i) returns an array, so this sytax
$er->GetMessage($i)["header"]['fromaddress']
seems like it would work. So, I'm at a loss. The arrow syntax doesn't make sense to me at all, because 'fromaddress' is not a member of 'header' — 'header' is not an object.
What am I missing? I did a search on "Parse error: syntax error, unexpected '[', expecting ',' or ';'" and I found one match. The solution was "- the php wasn't on automatic update so now it is the site is working fine." I don't think this applies to my issue.
The code is below.
Line 23, the line that triggered the error message, is in the for loop.
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]->fromaddress;
This is php between body tags:
for ($i=0;$i<$er->GetInboxCount();$i++)
{ // fromaddress, date, subject are from imap_headerinfo
echo br.br;
echo "<h3>Message received from: </h3>" . $er->GetMessage($i)["header"]['fromaddress'];
echo br.br;
echo "<h3>Message received on: </h3>" . $er->GetMessage($i)["header"]['date'];
echo br.br;
echo "<h3>Subject: </h3>" . $er->GetMessage($i)["header"]['subject'];
echo br.br;
echo "<h3>Message in text format:</h3>" . $er->GetMessage($i)['body_text'];
echo br.br;
echo "<h3>Message in html format: </h3>" . $er->GetMessage($i)['body_html'];
Try to use this:
$foo = $er->GetMessage($i);
echo "<h3>Message received from: </h3>" . $foo["header"]->formadresss;

PHP Syntax Check: Parse error: syntax error, unexpected [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Cant figuer out the problem with my code. Theres a syntax error,and i just cant spot it
Checked it here - http://phpcodechecker.com/ , and got this as an answer -
Parse error: syntax error, unexpected ''.$val[''
(T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in your code on
line 10
Here is the code -
<?php
include "products.php";
foreach($products as $key=>$val)
{
echo '<div style="float:right;text-align:center;margin:20px;">';
echo '<IMG src="img/'.$val['category'].'/'.$val['image'].'" WIDTH="94" HEIGHT="94" BORDER="0" ALT=""><br />';
echo $val['name'].'<br />';
echo '₪ '.$val['price'].'<br />';
echo '<a onmousedown="parent.AddItemToCart(''.$val['id'].'' ,''.$val['name'].'','img/'.$val['category'].'/'.$val['image'].'','.$val['price'].'')"></a><br/>';
echo '</div>';
}
?>
Replace
echo '<a onmousedown="parent.AddItemToCart(''.$val['id'].'' ,''.$val['name'].'','img/'.$val['category'].'/'.$val['image'].'','.$val['price'].'')"></a><br/>';
to
$imgtag = 'img/'.$val['category'].'/'.$val['image'];
echo '<a onmousedown="parent.AddItemToCart(\''.$val['id'].'\',\''.$val['name'].'\',\''.$imgtag.'\',\''.$val['price'].'\')"></a><br/>';
The unescaped ' terminates the string before you want it to. Try:
echo '<a onmousedown="parent.AddItemToCart(\''.$val['id'].'\' ,\''.$val['name'].'\','img/'.$val['category'].'/'.$val['image'].'','.$val['price'].'\')"></a><br/>';
or use double quotes:
echo "<a onmousedown=\"parent.AddItemToCart('".$val['id']."' ,'".$val['name']."','img/".$val['category']."/".$val['image']."','.$val['price']."')\"></a><br/>';
Reason: The reason of this happening, is that you use ' to start and end your string, but your string also contains the ' character. This way the string ends at the position you enter ' and is confused by the following symbols. To prevent this, you escape the symbols using a backslash \ like so: 'some string containing a \' character'
Change:
echo '<a onmousedown="parent.AddItemToCart(''.$val['id'].'' ,''.$val['name'].'','img/'.$val['category'].'/'.$val['image'].'','.$val['price'].'')"></a><br/>';
For this:
echo "<a onmousedown='parent.AddItemToCart(".$val['id']. ',' .$val['name']. ',img/'.$val['category'].'/'.$val['image'].','.$val['price'].")></a><br/>";
Change the code with given code
<?php
include "products.php";
foreach($products as $key=>$val)
{
echo '<div style="float:right;text-align:center;margin:20px;">';
echo '<IMG src="img/'.$val['category'].'/'.$val['image'].'" WIDTH="94" HEIGHT="94" BORDER="0" ALT=""><br />';
echo $val['name'].'<br />';
echo '₪ '.$val['price'].'<br />';
echo '<a onmousedown="parent.AddItemToCart('.$val['id'].','.$val['name'].'','img/'.$val['category'].'/'.$val['image'].','.$val['price'].')"></a><br/>';
echo '</div>';
}
?>

Categories