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>');
}
?>
Related
echo '<br />'.utf8_encode($article["texte_article"]);
I would like to have the text to use a css class "art". $article is a table, and texte_article is the selected column in the database.
echo '<br />''<div class=\"art\">'.utf8_encode($article["texte_article"])</div>;
It was a try but didn't work. Do you know why my syntax doesn't work/where I should put the class "art" ?
You are forgetting to add the end of the div in as a string, and you so it is messing up your php:
echo '<div class="art">'.utf8_encode($article["texte_article"]).'</div>';
There is an error in string concatenation. try this:
echo "<br /><div class='art'>".utf8_encode($article["texte_article"])."</div>";
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.
I've been trying to make a button that changes into a different image once rolled over with the mouse, but the code being inside of an echo command has caused some complications. This is the php code I tried to use, which otherwise simply displays the image when the onmouse functions are removed:
if ($pg > 0) { echo ('<div class="next"><img src="/images/prevpage.gif" onmouseover="this.src='/images/prevpagehl.gif';" onmouseout="this.src='/images/prevpage.gif';"/></div>'); }
Using this code causes the following error to appear:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/wintblxq/public_html/index.php on line 145
Are there any changes to the syntax I can make to get this to function properly, or do I need to attempt a new approach to this?
You need to escape your quotes (your ticks actually):
if ($pg > 0) {
echo '<div class="next"><img src="/images/prevpage.gif" onmouseover="this.src=\'/images/prevpagehl.gif\';" onmouseout="this.src=\'/images/prevpage.gif\';"/></div>';
}
You need to escape the single quotes in the onmouseover and onmouseout javascript:
if ($pg > 0)
{
echo ('<div class="next"><img src="/images/prevpage.gif" onmouseover="this.src=\'/images/prevpagehl.gif\';" onmouseout="this.src=\'/images/prevpage.gif\';"/></div>');
}
PHP is confusing these with the end of the string.
You first need to escape your single quotes with a Backslash example:
<?php echo '<p onmouseover="alert(\\'SIngle Quotes\\');">YAY</p>';
An easier way to write php and to see it (In my Opinion) is to Seperate HTML from php. With your code here is how i would write it.
<?php if ($pg > 0) { // PHP Scripts ?>
<!-- HTML Tags and text -->
<div class="next"><img src="/images/prevpage.gif" onmouseover="this.src='/images/prevpagehl.gif';" onmouseout="this.src='/images/prevpage.gif';"/></div>
<?php } ?>
This way you don't have to worry about escaping all of your single quotes, and you can see it nicer.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get useful error messages in PHP?
Ive started on part of my new year resolution and decided to learn php, as part of it im trying to parse in an xml feed, and echo out the name of the events wrapped in <a> tags linking them back to the events page on the xml feed's site.
I think ive got it all in but i cant seem to see why this isnt working im just getting a blank page, if some one could point me in the right direction it would be much appreciated, cheers
<?php
// F1 W/H xml feed
$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N');
foreach ($xml->response->williamhill->class->type as $type) {
$type_attrib = $type->attributes();
echo "<h2>".$type_attrib['name']."</h2>"; //Title - in this case f1 championship
} ?>
<ul>
<?php
foreach($type->market as $event) {
echo "<li>";
echo "<a href="$event_attributes['url']">";
echo $event_attributes['name'];
echo "</a>";
echo "</li>";
}
?>
</ul>
echo "<a href="$event_attributes['url']">";
try changing that line to
echo "<a href=\"".$event_attributes['url']."\">";
The Php parser is pretty funny about this. Usually you pick one and just stick to it, or use both single quotes and double quotes as you please. Just remember that strings with double quotes are parsed for variables.
$hello = "Hello";
echo "$hello master";
is the same as
$hello ="Hello";
echo $hello.' master';
When you are testing your PHP scripts, you'll find it useful to switch on errors - then PHP will actually tell you why it isn't showing you anything:
error_reporting(E_ALL);
Normally you will have missed a ; or mis-typed a variable name.
in your case the error is here:
echo "<a href="$event_attributes['url']">";
You have accidentally ended the string with a double quote, so PHP thinks the string ends here:
echo "<a href="
This is where using single-quotes can be very handy because your double quotes won't then close the string.
echo '<a href="' . $event_attributes['url'] . '">';
The main difference between single and double quotes in PHP is that double quotes has special clever parsing rules and single quotes doesn't. For example:
$myVar = "BLAH";
echo "Example $myVar"; // Example BLAH
echo 'Example $myVar'; // Example $myVar
In your unordered list, you should use a dot to concatenate your string, and escape your double quotes like this:
echo "<a href=\"".$event_attributes['url']."\">";
Instead of
echo "<a href="$event_attributes['url']">";
Your example throws and error because you haven't used proper string concatenation. However, even with correct concat, it would render as <a href=http://someurl>, and you'd need to add the double quotes according to html standard. Hence you have to double quote.
if you want to not be troubled by having to switch between using a ' or a " then i suggest using the php alternative syntax php alternative syntax
with the given code it would look like
<?php
// F1 W/H xml feed
$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N');
foreach ($xml->response->williamhill->class->type as $type) {
$type_attrib = $type->attributes();
echo "<h2>".$type_attrib['name']."</h2>"; //Title - in this case f1 championship
} ?>
<ul>
<?php foreach($type->market as $event):?>
<li>
<a href="<?php echo $event_attributes['url']; ?>">
<?php echo $event_attributes['name']; ?>
</a>
</li>
<? endforeach;?>
</ul>
one advantage this would bring is that it would produce cleaner code since you can clearly distiguish your php code from your html which is the presentational part at the price writing all those other <?php ?> and as what others would claim a performance degradation. the choice is yours
Change
echo "<a href="$event_attributes['url']">";
for
echo "<a href=".$event_attributes['url'].">";
You are missing the periods in your second echo, where you have your $event_attributes['url']
<?php
foreach($type->market as $event) {
echo "<li>";
echo "<a href=".$event_attributes['url'].">";
echo $event_attributes['name'];
echo "</a>";
echo "</li>";
}
?>
I would recommend you to enable your error log, it would allow you to know the line with problems in any of your scripts.
How do I go about using an image as a link in php? I have never put two html elements together in one echo so it's kinda new for me.
Here's my code:
htmltest.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?
require("includes/conn.php"); //link to the database
?>
<html>
<title>HTML with PHP</title>
<body>
<?php
echo "<img src="homelogo.jpg" />";
?>
</body>
</html>
That's my code. I get the following error:
PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home6/dreamsm2/public_html/htmltest.php on line 11
Can anyone tell me what I'm doing wrong? Any help would be appreciated.
Change the line to:
echo '<img src="homelogo.jpg" />';
OR
echo "<img src=\"homelogo.jpg\" />";
The problem, as the error somewhat suggests, is that the PHP interpreter can't figure out where your string is supposed to start and end. Using \" escapes the quotes. Using ' around the string gives a unique string delimiter around the string, so you are free to use double quotes inside.
Note, if you needed both single and double:
echo '<img src="homelogo.jpg" />';
You can also use ' instead of " for strings, e.g.
This works: echo '"Hello!"'; => "Hello!"
This wont work: echo "'Hello'";
SIMPLY DO THIS:
echo '<img src="Downloads_clip_image010.jpg" />';
For WordPress
<div class="floatLeft">
<a href="http://trophydevelopers.com">
<img src="<?php bloginfo('template_url'); ?>/images/powered-by.png">
</a>
</div>