Grodo Posted July 30, 2007 Share Posted July 30, 2007 I cant figure out how to echo in a color. Here is my code echo "<font color='#ff1200'>State / Territory Field Missing<br></font>"; the error that i receive is Parse error: parse error, unexpected T_IF in /home/galaxyto/public_html/phpharvest.php I remove the font tag and the script works fine. Thank You Grodo Quote Link to comment Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Share Posted July 30, 2007 there is no <font color> tag its <style font-color:"";>i belive is the problem im not positive Quote Link to comment Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 there is nothing wrong with the syntax of that line to throw up an error...it must be elsewhere on the script...as for the <font> tags I know nothing about that, I use CSS, so can't tell you if the html is right or not. post the rest of the script. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 30, 2007 Share Posted July 30, 2007 The echo is not the problem. We'll need some more code... Read the error code "unexpected T_IF". There is an if where PHP did not expect it. Look for an if. Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2007 Share Posted July 30, 2007 there is no <font color> tag Indeed there is. There is no parse error in the code youv'e provided. Can we see a few lines previous? Quote Link to comment Share on other sites More sharing options...
sstangle73 Posted July 30, 2007 Share Posted July 30, 2007 The font element was deprecated in HTML 4.01. but yah more code would help Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 30, 2007 Share Posted July 30, 2007 The font element was deprecated in HTML 4.01. but yah more code would help PHP doesn't understand HTML. All it does is echo strings. It doesn't care what that string contains. Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 I removed the color tags and it works like a charm how ever only in black text. When I tried it with style I received a different error. Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/galaxyto/public_html/phpharvest.php on line 197 197 is the line with the font tags. I tried <style font-color:"red">Error Text</style> <style font-color:"red";>Error Text Is there another way to print out text in PHP? I Know my code is messy sorry about that :-/ // Ok lets validate some parameters! With error reporting! //First we make an array to hold the error code information $errorcodes = array('ok', 'ok', 'ok', 'ok', 'ok', 'ok'); if ($db_name == "") { $errorcodes[0] = ename; } if ($db_snumber == "") { $errorcodes[1] = esnumber; } if ($db_city == "") { $errorcodes[2] = ecity; } if ($db_state == "") { $errorcodes[3] = estate; } if ($db_zip == "") { $errorcodes[4] = ezip; } if ($db_country == "") { $errorcodes[5] = ecountry; } // Code that gives the ok to process for ( $i = 0; $i<6; $i++ ) { if ( $errorcodes[$i] == "ok" ) { $process == TRUE; } else { $process == FALSE; } } if (isset($db_name) && isset($db_snumber) && isset($db_city) && isset($db_state) && isset($db_zip) && isset($db_country) && $process == TRUE) { // Write values to data files code if i posted it would be to long (the code works) } else { // Lovely Error Codes :-) if ( $errorcodes[0] == "ename") echo "<style font-color:"red">State / Territory Field Missing<br></style>"; if ( $errorcodes[1] == "esnumber") echo "Street Number Missing<br>"; if ( $errorcodes[2] == "ecity") echo "City Field Missing<br>"; if ( $errorcodes[3] == "estate") echo "State Field Missing<br>"; if ( $errorcodes[4] == "ezip" ) echo "Postal Code Field Missing<br>"; if ( $errorcodes[5] == "ecountry") echo "Country Field Missing<br>"; } Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 30, 2007 Share Posted July 30, 2007 Change echo "<style font-color:"red">State / Territory Field Missing<br></style>"; to echo "<style font-color:'red'>State / Territory Field Missing<br></style>"; OR echo "<style font-color:\"red\">State / Territory Field Missing<br></style>"; OR echo '<style font-color:"red">State / Territory Field Missing<br></style>'; Quote Link to comment Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 if ( $errorcodes[0] == "ename") echo "<style font-color:"red">State / Territory Field Missing<br></style>"; ///you are missing your curly brackets around each if statement if ( $errorcodes[1] == "esnumber") echo "Street Number Missing<br>"; ///should be like below if ( $errorcodes[2] == "ecity") {echo "City Field Missing<br>";} if ( $errorcodes[3] == "estate") echo "State Field Missing<br>"; if ( $errorcodes[0] == "ezip" ) echo "Postal Code Field Missing<br>"; if ( $errorcodes[0] == "ecountry") echo "Country Field Missing<br>"; } Report to moderator Logged Quote Link to comment Share on other sites More sharing options...
envexlabs Posted July 30, 2007 Share Posted July 30, 2007 <style> isn't a tag unless it's used in the head. trying using <p style="color: red;">Text</p> Inline styles are the greatest way of doing things, but they can get the job done. You could also just assign a class in php of red; .red{ color: red; } then use <p class="red"> Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2007 Share Posted July 30, 2007 Do as Daniel0 suggested. calabiyau, curly braces are optional with simple statements. Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 Daniel0 Code fixed t_string error but still prints in black is there another function to print out errors? envexlabs: <p style="color: red;">Text</p> just made the T_String error occur Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 30, 2007 Share Posted July 30, 2007 if you are starting your echo statement with double quotes you must escape any double quotes within your string. The same applies to single quotes too. So to echo out this: <p style="color: red;">Text</p> you'd use echo "<p style=\"color: red;\">Text</p>"; // OR // echo '<p style="color: red;">Text</p>'; Please re-read Daniel0 echo examples in this post Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 I figured it out! I just used the print method instead of echo Daniel0 was right echo command does not understand html. this is my new code print "<font color ='red'>State / Territory Field Missing<br></font>"; Thanx to every one who helped! I will donate to this great resource! Grodo Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 30, 2007 Share Posted July 30, 2007 print is the same as echo ... Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 Hmmm :-/ Then why does print work for me but echo does not? Must be a server issue then Quote Link to comment Share on other sites More sharing options...
jscix Posted July 30, 2007 Share Posted July 30, 2007 It didnt have anything to do with the function you used to print the html. When you use: " Any Following "s must be escaped,( Escape is \ ||| So to escape " you would type \" ) until the closing "; If you dont want to escape every ", you can also use a single quote ' $variable = "this is my 'example' see?"; // this works .. It also works the other way: $variable = 'blah blah "example" ya'; nothing to do with print or echo.. Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 but the thing is that echo printed in black ink and print printed in the right color Quote Link to comment Share on other sites More sharing options...
jscix Posted July 30, 2007 Share Posted July 30, 2007 You seem like you dont understand alot of the underlying mechanisms of programming .. html and so on. It would do you good to read up a bit on these.. it will help alot in your programming. Buy/checkout some books on HTML, CSS and PHP. Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Author Share Posted July 30, 2007 This is my first time coding in php :-x I just kind of jumped into it I have 2 years of Java coding exp so it wasnt so bad. Thanks for all your help guys. LOL im just goign to drop this before a flame war breaks out over PHP echo vs print lol It be like the Nintendo Ds vs PSP fan boys; only change would be echo method vs print hahahaha! I like this community so lets keep the hatred out :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.