PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to format a line of text that is echoed using CSS following some code I found online, but can't get it to work. When I click on the created class it shows no CSS exists. I had put the style in my styles within the page, which is a combination of php and html all in one.
<!-- css -->
p.paragraph {
text-align: center;
color: #000;
}
<?php
echo '<p class="paragraph">Thank you. We will be contacting you shortly with our best price for your request. Back to site home page</p';?>
echo "<p class='para'>Thanks for submitting the permission form for $activity</p>";
I switched the single and double quotes because it did not work with the original single around the echo and double on the class and another site suggested this change.
I ran a test with just the code from a sample alone and it worked fine, with single and double quotes as is. I also noted in the sample that the <span> was outside the php, but the code would work even if I removed the <span> tag and just went with the <p class> inside the echo. The css also showed up when I clicked on the class, which it doesn't do in my actual file.
<!-- css -->
<style type="text/css">
<!--
.paragraph {
text-align: center;
color: #00CC66;
}
-->
</style>
<span class="paragraph">
<?php
echo '<p class="paragraph">Thank you. We will be contacting you shortly with our best price for your request. Back to site home page</p';?>
</span>
However, when I tried this on my file, no formatting worked no matter how I tried - with or without span tags, etc. Span tag also stopped the echo from echoing my variable. I'm very frustrated.
The code that had the missing end tag is not the code I'm concerned with - that was the sample code, which by the way worked fine even with the missing tag. It is the other code with the class "para" that I am trying to solve. I have tried it with and without both span and paragraph classes, using each individually, etc - just still won't work.
dmwesq wrote:The code that had the missing end tag is not the code I'm concerned with - that was the sample code, which by the way worked fine even with the missing tag.
You won't be concerned with it now but just try to validate that html code, then you will notice it's absence.
Do you only have one the CSS for the para class or the code for the para class and the paragraph class?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Again, the code I need to focus on is my own, not the sample code which I have borrowed from. I've tried my code with variations including closing tags, using P class, span class, etc.
Here is my current CSS:
.para {
text-align: center;
color: #00CC66;
}
<?php
}
else {
mail( "info@*****.org", "Permission Form",
"Activity: $activity\n
Activity Date: $activity_date\n
Location: $location\n
Scout Name: $scoutname\n
Others Attending: $attending\n
Parent/Guardian: $parent\n
Email: $email\n
Primary Phone: $primaryphone\n
Alternate Phone: $alternatephone\n
Alternate Contact: $alternatecontact\n
Alternate Contact Phone: $alternatecontactphone\n
Any Medical Change Since Last Physical: $physical\n
Describe Changes: $other\n
Any change in medications: $medicine\n
Describe Changes: $other2\n
Is Parent/Guardian Transporting: $transport\n
If yes, number of other scouts you can transport: $scouts\n
If not, have transport arrangements been made: $transport2\n
Name of family transporting: $other3\n
Legal Acknowledgement: $legal\n
List any additional information: $additional",
"From: $email" );
header ('Refresh: 5; http://www.*****.org/events.shtml');
echo "<span class='para'>Thanks for submitting the permission form for $activity.</span>";
}
?>
Where is your CSS? In a style sheet, or as part of the head section of your html? If it is in a style sheet, check that you haven't made a error in the link to your style sheet (eg specifying a wrong path). Then clear the browser cache. Browsers frequently cache style sheets, and don't always notice when they have changed.
If you have a page of mixed html and php, the php is parsed and executed first, and the html afterwards. The style bit in your head section is outside the <?php ... ?> tags, I guess, so it will be sent to the browser after the echo command has sent "Thanks for submitting the permission form for $activity".
What to do about it? Well, the real solution is to write your code so that the logic (basically the php) and the presentation (html) are completely separate. But for a quick fix you could just do:
dmwesq, I don't think it's a php problem. I would check and double check to make sure everything is spelled right, no missing semicolons or closing braces, etc, etc.
I'm still stuck with my formatting issue. I have everything working fine - the echo gives back my message including the variable, the redirect works fine, but each time I try to add any css into this whether inline, or with a style, I get errors. If I put CSS code in style before the php I get headers already sent, and the reference goes back to whatever line has style=text/css. I am very confused and I guess I could live without the formatting but I know it is supposed to be able to be done - just can't figure out how.