Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE - php

I might have a syntax error or something but I don't see nothing.
<select id="cd" name="cd">
<?php
while($row=mysql_fetch_array($cdresult)) {
echo "('<option value='$row['Poblacion']'></option >'.'<br />)";
}
mysql_close($link);
?>
</select>
On the echo line, I have the error :
[error] [client] PHP Parse error: syntax error, unexpected
T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or
T_NUM_STRING in /var/www/slimtest/views/nuevo.php on line 89
Maybe you can help, because I don't see the error D"=

When using array variables inside of strings it's usually better to use the complex syntax:
echo "('<option value='{$row['Poblacion']}'></option >'.'<br />)";
Alternatively you can remove the quotes in the array key:
echo "('<option value='$row[Poblacion]'></option >'.'<br />)";
PHP String Variable Parsing

This should work:
<select id="cd" name="cd">
<?php
while($row=mysql_fetch_array($cdresult)) {
echo "<option value=".$row['Poblacion']."></option><br/>";
}
mysql_close($link);
?>
</select>

Try changing echo line to this:
echo '<option value="' . $row['Poblacion'] . '"></option >';

This line is a mess
echo "('<option value='$row['Poblacion']'></option >'.'<br />)";
First off, you can't use other characters around an <option> tag (the <br> tag is meaningless there). And then you leave the text of the tag blank. Finally, you're using double quotes around the whole thing, leaving PHP to try and interpret it. My bet is you're trying to do this instead.
echo '<option value="' . $row['Poblacion'] . '">' . $row['Poblacion'] . '</option>';
This will generate a proper tag AND populate it with the text of your field as well (so users can see what they're selecting). The way you had it, even if it were proper HTML, you'd have a dropdown of nothing but blank entries.

Related

display div inside php using echo

I want display my button if it have isset($_GET). I am trying to do like this.
<?php if(isset($_GET['project_id'])){
echo '<div class="add_btn_primary"> Project Users </div>';
}?>
its giving me error like
Parse error: syntax error, unexpected 'project_id' (T_STRING), expecting ',' or ';' in C:\xamppp\htdocs\mayank\add_project.php on line 101
I am not getting idea what I should do for echo project_id in div. Let me know if someone can help me for that.
Thanks
Thats incorrect to use echo inside another echo and how can you start a new php tag without closing the first.
The correct way is to concatenate the variable along the string passed in echo, here is how
<?php if(isset($_GET['project_id'])){
echo '<div class="add_btn_primary"> Project Users </div>';
}?>
instead of breaking the php tags break the ' quotes to concatenate the value in the string.
Why do you need again tag inside echo just use it as below:
<?php
if(isset($_GET['project_id']))
{
echo ('<div class="add_btn_primary"><a href="manage_project_users.php?project_id='.$_GET["project_id"].'>Project Users</a></div>');
}
?>

Parse error: syntax error, unexpected 'href' (T_STRING), expecting ',' or ';'

Getting error in this code...please help... i have changed it also like....
echo "<td>" Download"</td>";
or
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
still getting the error.
This should work for you:
(You don't concat the strings correctly and you forgot quotes for the href tag)
echo "<td><a href='get_file.php?id=" . $row['quote_id'] ."'>Download</a></td>";
Concatenation is your friend when outputting HTML.
echo '<td>Download</td>';
I usually try to put the single quotes on the outside and the double quotes on the inside because it's easier for me to manage.

php quotes in quote in quotes

I have the following code:
echo "<script type='text/javascript'>
iframe0document.getElementById('jform_articletext').value = '<?php echo \"<p align='center'><iframe src='aufgaben/'+cookieValue+'/'+cookieValue+'.html' width='322' height='497' frameborder='0'></iframe></p>\";?>';}</script>";
but it has a problem with the quotes, I tried almost everything but it says always:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /usr/www/users/mathea/joomla/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 118
Ok the question should be changed to php nesting in php. I need a way to negate the offect of the php nesting like it's possible for quotes with \"
Updated
You made PHP tags within echo. That's pretty wrong!
As I understand OP:
$text = htmlentities('<?php echo \'<pre><p align="center"><iframe src="aufgaben/"+cookieValue+"/"+cookieValue+".html" width="322" height="497" frameborder="0"></iframe></p></pre>\'; ?>');
echo "<script type='text/javascript'>
iframe0document.getElementById('jform_articletext').value = ".$text.";
</script>";
You need htmlentities function to encode characters to their html equivalents and print out php tags az plain text.
But you are already in "php mode"!
Why you reopen php tag on
'<?php echo
?
Then, what is "iframe0document.getElementById"?

HTML inside sprintf

Is it possible to do something equivalent to this in PHP >= 5.3.0?
echo sprintf(_('By %s'), ?>
<span class="author-name"><?php echo $authorName; ?></span>
<?php ); ?>
If I use said syntax I receive the following error, which is being caused by the first ?>,
Parse error: syntax error, unexpected '?>' in ...
Basically, what I'm trying to do is to insert HTML with PHP tags inside, as a parameter for the sprintf function without treating the HTML as a string ('<span class="author-name">' . $authorName . '</span>').

How to use onClick within php?

I have a php script I want to echo some html with. I keep getting this error:
Parse error: syntax error, unexpected T_ECHO
echo "<a onClick=\"" window.location.href='test.php'; "\" class='container'>test</a>";
Try this:
echo "<a onClick=\"window.location.href='test.php'\" class='container'>test</a>";
You aren't escaping the double quotes correctly. Each double quote that you want to escape should be written as \" . Looks like you were trying to open and close an escaped block or something.
echo "<a onClick=\"" window.location.href='test.php'; "\" class='container'>test</a>";
vs
echo "<a onClick=\"window.location.href='test.php';\" class='container'>test</a>";

Categories