jamesjmann Posted February 2, 2011 Share Posted February 2, 2011 Hey, I posted a thread before about a news cms I've been developing. And right now I'm trying to flesh out the css of the articles I post on the home page. Now the problem I having is everytime I place a <span class=""></span> or <p class=""></p> or even <div class=""></div>, my web page does NOT load, and instead gives me an error. Parse error: syntax error, unexpected T_STRING in /home/content/d/j/s/djsmiley/html/index.php on line 405 Now, I know it's possible to add css to a PHP echo statement, but I'm clearly doing something wrong. Here's the code for the php echo statement with the css included: <? include("dbconnect.php"); //include the file to connect to the database $getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC"); //query the database for all of the news while($r=mysql_fetch_array($getnews)){ //while there are rows in the table extract($r); //remove the $r so its just $variable echo("<br><span class="NewsID">$type</span> <span class=h2>$title</span><br><br> <em>posted by <strong>$user</strong> | added on $time</em><br><br> $message<br><br> <label class="fltlft2"><img src="../../Websites/DJSmiley.Net/images/Icons/Arrows/Right.png" width="20" height="20"/></label><a href=$url>Read more - $url</a> <div class="newsLikeShareRate"> <table width="100%" border="0"> <tr> <td width="3%" height="21"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script> <fb:like href="$url" show_faces="true" width="450" font="arial"></fb:like> </td> <td width="65%"><a name="fb_share" id="fb_share4" type="icon_link" share_url="$url">Share</a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></td> <td width="32%">Rate this article: </td> </tr> </table> </div>"); } ?> If you're wondering why there's a facebook script in there, I made it to where everytime a new post is added, a facebook like and share button are added, and are assigned the url I specify when the article is posted. Well, I think that's it for the code. Can anyone tell me what I'm doing wrong? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 2, 2011 Share Posted February 2, 2011 When using double quotes within a double quoted string, or single quotes within a single quoted string, they must be escaped with a backslash. echo "Dave said, \"Hello\" to everyone he saw that day."; echo 'That\'s Jimmy\'s beach ball.'; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 2, 2011 Share Posted February 2, 2011 You have surrounded your string with double quotes and have double quotes in the HTML. As soon as PHP sees the second double quote, that terminates the string and you get an error. Just surround your string with single quotes. Also you don't need to put parenthesis around the string when using echo. Ken Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 2, 2011 Author Share Posted February 2, 2011 Ok. Well, I achieved a similar result when eliminating all of the quotes within the echo statement as a whole. I just googled it, and someone pretty much said what you guys said. Thanks! 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.