PHP Parse error: syntax error, unexpected ',' [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi guys can anyone help to figure out what's wrong in my code it showing unexpected ','
$list1 .= '<tr onmouseover="this.style.backgroundColor=','#ffff66',';" onmouseout="this.style.backgroundColor=','#d4e3e5',';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';

, is used for passing multiple parameters to echo, not for concatenating strings to add to be stored in a variable. use . instead

You can rewrite it like this, escaping the single quotes in the javascript:
$list1 .= '<tr onmouseover="this.style.backgroundColor=\'#ffff66\';" onmouseout="this.style.backgroundColor=\'#d4e3e5\';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';

You are not properly concatenating the string/escaping the quotes. You had unnecessary commas. My example also uses double quoted strings so you don't need concatenation
$list1 .= "<tr onmouseover=\"this.style.backgroundColor='#ffff66;'\"
onmouseout=\"this.style.backgroundColor='#d4e3e5'\">
<td>$ver</td><td>$ver2</td></tr>";

To avoid to escape quotes: you can use the heredoc syntax:
$list1 .= <<<EOD
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>$ver</td><td>$ver2</td>
</tr>
EOD;

try this-
$list1 .= "<tr onmouseover='this.style.backgroundColor='#ffff66';' onmouseout='this.style.backgroundColor='#d4e3e5';'><td>".$ver."</td><td>".$ver2."</td></tr>";
working fine for me.

Related

My code is not working ($h.= ') [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Can anyone help me for this why doesn't my code work?
$h.= ' 'mysql_result($res,$z,"name")'';
It gives me an error because of the <a href
$h .= ''.mysql_result($res,$z,"name").'';
Should work now
. before mysql_result and after.
Also take a look here it will help you to understand String Operators and etc.
You need to concatenate.
$h.= ' ' . mysql_result($res,$z,"name") . '';
Anyway, I would suggest you to put mysql_result($res,$z,"name") into a variable, to increase readability and avoid executing the function every time you call it.
I mean:
$name = mysql_result($res,$z,"name");
$h.= ' ' . $name . '';
Try this
$h.= ''.mysql_result($res,$z,"name").'';
You are missing . the concatenation operator

PHP function and HTML output parse error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
There is something wrong with this code, I cant make it go trough... the situation is that
the difficulty-meter needs to be checked , if it is filled, execute a mix of HTML and PHP. I'm learning php and got stuck in this functions...
Im using WP and WPML to translate that's why I add the -__e('Difficulty', 'projectname')': as a string. I get a error ,
Parse error: syntax error, unexpected 'tpage' (T_STRING), expecting ',' or ';' in /homepages/46/d448593520/htdocs/wp-content/themes/site/document.php on line 218
My full code is
<?php
// CHECK IF DIFFICULTY FIELD EMPTY
$diffcheck = get_post_meta($post->ID, 'wpcf-difficulty-meter', true);
if ( $diffcheck) {
echo "<ul class="tpage-list">
<li>'
-__e('Difficulty', 'projectname')':
'</li><li>'
types_render_field('difficulty-meter', array('output'=>'html','class'=>'tpage-difficulty'))
'</li></ul>";})
}
else {
// Show Nothing
}
// END
?>
The syntax highlighting shows your error: it's a quoting issue. You have to escape your double quotes inside of your string:
echo "<ul class=\"tpage-list\">
or use single quotes:
echo "<ul class='tpage-list'>
To complete what John Conde said, this part make no sense:
echo "<ul class="tpage-list">
<li>'
-__e('Difficulty', 'projectname')':
'</li><li>'
types_render_field('difficulty-meter', array('output'=>'html','class'=>'tpage-difficulty'))
'</li></ul>";})
Lets go through it:
// You have to keep track of concatenation. You started the string with ", you can't use it except to end string (or if you use \ like John Conde said)
// After the li: it seem like you wanted to add the value of the Difficulty thing, so you have to end your string and concaten it with a .
// Back to the strings and concaten it again to add the type render, since the string is now started with a ', I use a ' to end it
echo "
<ul class='tpage-list'>
<li>".-__e('Difficulty', 'projectname').':</li>
<li>'.
types_render_field('difficulty-meter', array('output'=>'html','class'=>'tpage-difficulty'))
.'</li>
</ul>';
I don't really see why you had a }) at the end, so I took it out

issues using an image src in php echo [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
im having trouble using an image search within php tags, is it possible?
My code bellow:
<?php
echo "<div id=reviewname>Name: ".$dname['name']."</div>";
echo "<div id=reviewseat>Seat: ".$dseat['seat']."</div>";
echo "<div id=srating>Sound: ".$dsrating['s_rating']."</div>";
echo "<div id=crating>Comfort: ".$dcrating['c_rating']."</div>";
echo "<div id=vrating>View: ".$dvrating['v_rating']."</div><br /><br/>";
echo "<div id=reviewcomment> Comments: ".$dcomment['comment']."</div>";
?>
I would like within these div's to be an image src example being:
echo "<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: ".$dsrating['s_rating']."</div>";
The above does not work, is it a syntactical issue?
Thanks
You need to escape the quotes inside the echo statement
echo "<div id=srating><img src=\"images/soundimg.png\" alt=\"Sound\" height=\"35\" width=\"35\"></div>Sound: ".$dsrating['s_rating']."</div>";
If not escaping, you can also use single quotes for attribute values.
echo "<div id=srating><img src='images/soundimg.png' alt='Sound' height='35' width='35'></div>Sound: ".$dsrating['s_rating']."</div>";
If you need to echo and in string u need to put " quotes, you can use single quote around ur string.
echo '<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: '.$dsrating['s_rating'].'</div>';
same for single quote.
But if you need both single & double quotes you can use any method and use \' or \"
Or you can have a very useful too, heredoc syntax.

php unexpected 'meta_value' (T_STRING) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
im getting this error but cannot figure out why
while($info = mysql_fetch_array( $data ))
{
echo itg_fetch_image('.$info['meta_value'].'); //the line giving error
Print "<tr>";
Print "<th>ID:</th> <td>".$info['meta_id'] . "</td> ";
Print "<th>VALUE:</th> <td>".$info['meta_value']. "</td> ";
Print "<th>DONE:</th> <td>YES</td> ";
}
if i comment out this line it shows fine in the value td, ive tried everthing. taking the dots out the taking the comments out then adding "". itg_fetch_image is http://www.intechgrity.com/automatically-copy-images-png-jpeg-gif-from-remote-server-http-to-your-local-server-using-php/#
the code is ment to be echo itg_fetch_image('url') and all meta_values return a url string
The quotes on the echo line are causing the problem.
It should look like this:
echo itg_fetch_image($info['meta_value']);
it seems that itg_fetch_image() is a function
try this:
echo itg_fetch_image($info['meta_value']);
you can just pass variable . do not need to use quotes.
You must write it as
echo itg_fetch_image($info['meta_value']);

echo out valuename in php [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
how can I print out a variable name in text in php?
I want to accomplish something as simple as having this:
echo "|" . "$myvariable" . "|";
print out this:
|$myvariable|
instead of this:
||
how can I accomplish this?
Use single quotes so that the variables don't get interpolated:
echo "|" . '$myvariable' . "|";
As others pointed out, use single quotes to show the variable name "as is".
echo "|" . '$myvariable' . "|";
Be sure to read this part of the manual.

Categories