PHP - Css & Html In Php Echo Statement
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.
Code: [Select] 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: Code: [Select] <? 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? Similar TutorialsI'm trying to input the results from a query into html, but I'm just getting the variable names rather than their values. I used single quotes for the echo statement, but I think I must need to switch to double to do that. But then I have problems with the double quotes from the class names (ex. class="SideBoxTitle"). Code: [Select] <?php // get user's videos from database $conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error()); $query = "SELECT * FROM haas12_test.videos"; $result = mysqli_query($conn, $query) or die ("Couldn't execute query."); while($row = mysqli_fetch_assoc($result)) { extract($row); echo ' <div id="topBox" class="mainVideoSideBoxes" > <div class="SideBoxTitle" ><h3> $vidtitle </h3> </div><!-- close SideBoxTitle --> <div class="sideBoxVidContainer"> <div class="SideBoxScreenCast" > $vidurl </div><!-- close SideBoxScreenCast --> <div class="SideBoxDesc" ><p> $viddesc </p> </div><!-- close SideBoxDesc --> </div><!-- close sideBoxVidContainer --> </div><!-- close mainVideoSideBoxes --> </div><!-- close mainVideoSideBoxes --> '; // end echo staement } ?> I am having a problem echoing a line of code. I am doing this on my local machine. Anyway, here are the to files involved... home.php <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; include $_SERVER['DOCUMENT_ROOT'] . '/includes/doctype.inc.php'; include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.inc.php'; ?> </head> <body> <div id="wrapper"> <!-- start horizontal navigation --> <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/topnav.inc.php'; ?> <!-- end horizontal navigation --> <div id="content"> <h1><?php echo htmlout($cattitle); ?></h1> <span class="desc"><?php echo ($catdesc); ?></span> <?php include $_SERVER['DOCUMENT_ROOT'] . '/info.php'; ?> </div> <!-- start footer --> <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc.php'; ?> <!-- end footer --> </div> </body> </html> and info.php <?php $result = mysqli_query($link, 'SELECT * From includes where catid ='.$_GET['id']); if (!$result) { $error = 'Error getting categories: ' . mysqli_error($link); include 'error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $inc[] = array('id' => $row['id'], 'include' => $row['include'], 'inc_orderby' => $row['inc_orderby'], 'inc_avail' => $row['inc_avail']); } foreach ($inc as $include): { echo "include $_SERVER['DOCUMENT_ROOT'] . '/includes/' . $row['include'];"; } endforeach; ?> I can't get the echo statement at the bottom of info.php echo "include $_SERVER['DOCUMENT_ROOT'] . '/includes/' . $row['include'];"; to show up correctly on the home.php page in this spot. include $_SERVER['DOCUMENT_ROOT'] . '/info.php'; what i am attempting to do is loop through some additional information relevant to the page a user selects on the site and display it. (I still have to set up some qualifying statements but this was just the first step to see if anything would show up) This is the parse error I get. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\info.php on line 18 I've tried messing with the quotes in the echo statement cause I'm sure they aren't right but I never came up with a quote combination that worked. I'm assuming that is the problem. Anyway thanks for taking a look. Welcome member. I am able to get data added to my db and when it gets to the welcome page I want it to welcome $firstname but it comes up blank. How can I fix my echo statement. <?php session_id(); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome</title> </head> <body> <?php /* Program: New_member.php * Desc: Displays the new member welcome page. Greets * member by name and gives a choice to enter * restricted section or go back to main page. */ if (@$_SESSION['auth'] != "yes") @include('Connections/connect_to_mysql.php'); $result = mysql_query("SELECT firstname FROM `Members` WHERE id='{$_SESSION['id']}'"); $row = mysql_fetch_array($result); echo "<html> <head><title>New Member Welcome</title></head> <body> <h2 style='margin-top: .7in; text-align: center'> Welcome, $firstName </h2>\n"; ?> <p>Your new Member accounts lets you enter the members only section of our web site. You'll find special discounts, a profile of matches, live advise for experts, and much more.</p> <p>Your new Member ID and password were emailed to you. Store them carefully for future use.</p> <div style="text-align: center"> <p style="margin-top: .5in; font-weight: bold"> Glad you could join us!</p> <form action="profile.php" method="post"> <input type="submit" value="Enter the Members Only Section"> </form> <form action="index.php" method="post"> <input type="submit" value="Go to Main Page"> </form> </div> </body> </html> Hello guys im new to php i been coding for like a week now, i need some help here i have been stuck for like 6 hours XD,is it possible to write an IF Statement inside an echo? //this is what i want to do // echo a table and a delete button // and if you click on the delete button it echoes out "DELETED" echo " <table width='528px'> <tr> <td> </td> <td> <center><font size='5'>$tittle</font></center><br> </td> </tr> <tr> <td> </td> <td> $message </td> </tr> <tr> <td> </td> <td> <font size='1'>Posted By:<font color='green'>$author</font> on <font color='gray'>$date</font> at <font color='gray'>$time</font></font> <input id='delete' name='delete' type='submit' value='Delete' > if ($_POST['delete']) { echo "DELETED"; } <td> </td> </tr><br><br> </table> "; Hello,
I am working on this function that echo's out images from my database restricted to 10 images with 4 default images if the database is empty.
<?php $query = mysql_query('SELECT image_id, image_expiry FROM images ORDER BY RAND() LIMIT 10'); $i = 0; class myCounter3 implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter3; while ($row = mysql_fetch_array($query)) { if($i % 10 === 0) { } echo '<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>'; $i++; } for (; $i <= 4; $i++) { echo '<img src="http://www.mysite.com/default.jpg" width="300" height="auto"/>' } ?>I need to include an image expiry function with the function above, but I am not sure how to properly include it. Here is my planned expiry function (each image as an expiry date). $today = date("Y-m-d", time()); $expiry = $row['image_expiry'] if( $today > $expiry) { ## ignore expired image } else { ## display image }Bottom line I need to exclude expired images from being echoed out in the first function. Thanks in advance. Everything I have tried hasn't worked. I want to add a space after $item in the below statement so that there is more space between the output of Item and Qty. I am using the Twitch API to tell if a user is live. I'm new to the Twitch API and PhP so please forgive me if I make any mistakes. Expand the Spoiler tags below to see the code. The code below SHOULD be telling me if a channel is not live or not. It tells me if they are live, but not if they are not live. I don't understand.
Spoiler
<?php if (!empty($_GET['channel'])) { $channel = $_GET['channel']; $dataArray = json_decode(@file_get_contents('https://api.twitch.tv/kraken/streams?channel='.$channel), true); foreach ((array) $dataArray['streams'] as $mydata) { if (!empty($mydata['_id'])) { echo "Channel is live<br><br>"; $uptime = $mydata['created_at']; $uptime = str_replace("Z", "UTC", $uptime); $uptime = preg_replace("/T/", "", $uptime, 1); echo "Twitch Uptime: ".$uptime."<br />"; date_default_timezone_set('UTC'); $localUptime = date('Y-m-dh:i:sT', time()); echo "UTC Local Time: ".$localUptime; } else { echo "Channel is not live"; } } } else { echo "No channel"; } ?> Code: [Select] echo("<p class=\"commentboxContainer\"><table width=100% border=0> <tr> <td bgcolor=\"#EEE\"><strong><p class=fltlft>$name </strong>says:</p></td> </tr> </table> <table width=100% border=0 bgcolor=\"#EEE\"> <tr> <td width=40%><img src=../images/Icons/People/Anonymous.png width=64 height=64 border=1 /></td> <td width=60%>$comment',0,6</td> </tr> </table> <table width=100% border=0> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft><em>$email</em></p></td> </tr> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft>added on $time</p></td> </tr> </table></p><br>"); Here's my echo statement for displaying comments by users. I want to add a substr (); function to limit the amount of characters of the $comment field. That way if a user makes a long comment it doesn't push the page down. I tried putting it after the echo (); but that didn't work. I also tried putting it before $comment and that didn't even work. I know that if I make two separate echo statements, this can be done, but the field "$comment" is displayed within a table that is part of the original echo statement, so what do I do? // Other code //echo "<table border='10' cellpadding='3' cellspacing='2'>"; This works echo "<table class="my-table">"; //This does not work echo "<tr><th>First Name</th><th>Last Name</th><th>Home Phone</th><th>Cell Phone</th><th>email</th></tr>"; // keeps getting the next row until there are no more to get ================ while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table ========================== echo "<tr><td>"; echo $row['first']; echo "</td><td>"; echo $row['last']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['cell']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> Error message: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/bayare27/public_html/content/pages/display_all_members1.php on line 29 Line 29 is: echo "<table class="my-table">"; <table class="my-table">" is a valid statement because It works in another program, but html not php I have to put a link that can be clicked around the first name and last name variables in the echo statement below. I also need to add a variable from the Select query to the link such as: 'www.phpfreaks.com/admin/customers.php?page=1&cID="VARIABLE HERE" &action=edit' I've tried a bunch of things and none seem to work. while($row = mysql_fetch_array($result)){ echo '<tr><td>' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>' . $row['plan_id'] . '</td></tr>'; David Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. I want the login script to echo out a statement, and then after 5 seconds (if the user hasn't clicked the link manually) I want it to redirect with the header redirect. I'm using the sleep function for the delay of the redirect. Here's the concerned portion of the login script: // check to see if the INPUT DATA matches the DATABASE COLUMNS! if ($nickname == $dbuser_name && sha1($password) == $dbuser_password) { // set a session after login $_SESSION['user_name'] = $dbuser_name; $_SESSION['user_id'] = $dbuser_id; echo "<center>You're logged in! <a href='01.php'>Click here</a> to go to the main page.</center>"; sleep(5); // seconds to wait header ('Location: 01.php'); // password incorrect error message } else { echo "<center>Incorrect password!</center>"; } But the echo statement never gets printed out, any idea why it gets swallowed by the sleep function? Hi I am new to PHP and this is my first post one here so appologies is this questions seems a bit dumb! I have an if clause such that if a button is pressed on my web page then i want to reload the page and include a new form on it. I am having a problem getting the $_SERVER['PHP_SELF'] command to work from iside a echo command. I must not be escaping the code correctly with back slashes: I currently have the line : echo"<form method=\"POST\" action=\"\<?$_SERVER['PHP_SELF']?\>\">"; However this doesnt seem to work as my page just doesnt display in the browser. Any advice is much appreciated. Thanks for taking the time to read. I've been working on my email screen, adding a video to it, and some Css. Which seems to work quite fine. However when the page returns to the original screen (represented by the code 1.) It collapses the video image. Makes it really long horizontally and thin vertically.
If I remove this first piece, showing that the email was sent successfully. if(isset($_GET['Message'])){ echo $_GET['Message']; } It returns to the screen fine and the video looks as it should. Code1:- <?php if(isset($_GET['Message'])){ echo $_GET['Message']; } $uri = $_SERVER['REQUEST_URI']; $uri_dir = getcwd(); ?> <!DOCTYPE html> <html> <head> <link href="/LifeSaverHTML/Details/Database/stylevid2.css" rel="stylesheet" type="text/css"> <h1 class = "titler"> LifeTube </h1> <p></p> </head> <body> <video class = "tube" controls src="examplevid.mp4"> Your browser does not support the video tag. </video> <p></p> <div style="margin: 0 auto; text-align: center"> <a href='/PHPMailer/index.php?id=<?=$uri?>&dire=<?=$uri_dir?>' class="linker">Email Security</a> </div> </body> </html>
I'm using this piece of CSS = Code2. I've set all the defaults padding etc to default for testing. * { margin: 0; padding: 0; } As I say it looks great. Apart from when it returns with the email successful message. The whole thing just deflates.
Code2:- * { margin: 0; padding: 0; } body { background: url('/LifeSaverHTML/Details/Database/backround.jpg') no-repeat center center fixed; height: 100%; background-position: center; background-repeat: no-repeat; background-size: cover; } .tube { display: block; margin: auto; width: 50%; height: 20%; border: 10px solid green; } .button { margin: 0 auto; display:block; text-align: center; } .linker { background-color: #23b83c; border: 2px solid #020353; color: whitesmoke; padding: 1em 1.5em; text-align: center; text-decoration: none; font-size: 1em; display: inline-block; width: 12%; border-radius: 5px; box-shadow: 3px 3px 8px 0 #000; /* h-offset v-offset blur spread color */ } .linker:hover { color: red; } .titler { width: 20%; text-align: center; margin: 0 auto; color: #FFFFFF; border: 5px ridge rgba(124,252,0); border-radius: 36px; background: #232323; text-shadow: 0 0 5px #FFF, 0 0 10px #FFF, 0 0 15px #FFF, 0 0 20px #49ff18, 0 0 30px #49FF18, 0 0 40px #49FF18, 0 0 55px #49FF18, 0 0 75px #49ff18; } nav { width: 80%; margin: 0 auto; } nav ul { list-style: none; overflow: hidden; } nav ul li { float: left; width: 20%; } nav ul li a { text-align: center; padding: 8px 0; display: block; width: 100%; background: #cdeb8e; /* Old browsers */ background: -moz-linear-gradient(top, #cdeb8e 0%, #b0ca34 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cdeb8e), color-stop(100%,#b0ca34)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #cdeb8e 0%,#b0ca34 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #cdeb8e 0%,#b0ca34 100%); /* Opera 11.10+ */ background: linear-gradient(to bottom, #cdeb8e 0%,#b0ca34 100%); /* W3C, IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#cdeb8e’, endColorstr=’#b0ca34′,GradientType=0 ); /* IE6-9 */ } nav ul li a, nav ul li a:focus, nav ul li a:visited, nav ul li a:hover, nav ul li a:active { color: #000; text-decoration: none; } nav ul li a:hover, nav ul li a:active { background: #b0ca34; /* Old browsers */ background: -moz-linear-gradient(top, #b0ca34 0%, #96c40d 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b0ca34), color-stop(100%,#96c40d)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #b0ca34 0%,#96c40d 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #b0ca34 0%,#96c40d 100%); /* Opera 11.10+ */ background: linear-gradient(to bottom, #b0ca34 0%,#96c40d 100%); /* W3C, IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#b0ca34′, endColorstr=’#96c40d’,GradientType=0 ); /* IE6-9 */ } nav ul li:first-child a { border-top-left-radius: 8px; border-bottom-left-radius: 8px; } nav ul li:last-child a { border-top-right-radius: 8px; border-bottom-right-radius: 8px; } Edited February 17, 2020 by JonnyDriller Here's the code, this is the PHP in my html contacts page (that IS in fact saved with a PHP extension): <div class = "centercontainer"> Hello, all... I seem to remember, like if I have a problem with a mysql_query() statement, and want find out why it keeps giving me an error, I'm often told to echo out the statement for debugging purposes. Can somebody remind me again how that's done... thanks! I have written this code but im not used to echoing html in php so I have errors. echo " <option value= '{$county['county']}'" if ($User['county'])==$county['county']) {echo "selected";} echo">{$county['county']}</option>"; } the server error is; syntax error, unexpected T_IF, expecting ',' or ';' Can somebody please point out how I have written it wrong? Hi everyone, First time post for me I am quite new to PHP so excuse the beginner question but I can't find and answer for it. I have a backend application that allows an admin to update the frontend homepage with a WYSIWYG html editor (Xinha). I store the html into mysql and retrieve the data for display on the front end homepage. The problem is the html is not rendering and displaying with the tags as text. When saving the data to the db I use htmlentities($data) and when retrieving I used html_entity_decode($data) before passing it to the template to be rendered. I am using a simple <?php echo $data ?> to display the data. On the same page I have <?php $testingHTML = "<p>This is some text with a <b>bold</b> word in it</p>" ?> followed down the page by an <?php echo $testingHTML ?> and that renders perfectly. So I must be doing something wrong? Thank you in advance and I hope that makes sense. Steve Hi im trying to echo out some html within php based on an if statement. Basically if you the is part of a club within a list item list the clubs, if they are not echo none within the list. Here is the code and below will be the error from the server. <?php // Query for finding out if the signed in user is part of any clubs and then display them here. $qMyClub = "SELECT clubID, name FROM clubs WHERE memberID = ".$User['memberID'].""; $rMyClub = mysql_query($qMyClub); $NumClubs = mysql_num_rows($rMyClub); if ($NumClubs>=1) { while($Clubs = mysql_fetch_assoc($rMyClub)){ echo"<li>My Clubs <ul> <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> </ul> </li>"; } else ($NumClubs==0) { echo" <li>My Clubs <ul> <li>None</li> </ul> </li>"; } } ?> and 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 /home/sites/index.php on line 78, referer: its referencing to the following line; <li><a href=\"members/myclub.php?club='$Club['clubID']'\">$Club['name']</a></li> I dont understand php enough to fix this can anyone help? Hi everyone, i have a user posting system and i want to echo data so that any HTML tags of any kind will be regarded as plaintext, so that it will have no effect on the webpage, thanks Jack |