membot Posted November 4, 2010 Share Posted November 4, 2010 I have a page that shows entries in a guestbook I'm making, and below the entries there is supposed to be a form to write an entry. Except, none of the HTML after the script to show the entries shows up on the page. I have no clue what's wrong. Here is the script to show the entries. $n is name, $d is date, $s is site (optional), and $m is message. $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } echo ' <tr> <td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;">'.$m.'</td> </tr></table><br> '; } flock($file, LOCK_UN); fclose($file); The file it is reading looks like this: |11:51 am, 3rd Nov 2010|Memoria|none|Hello. |11:51 am, 3rd Nov 2010|Memoria|http://sitehere|Hello again. |11:51 am, 3rd Nov 2010|Memoria|none|How are you doing? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/ Share on other sites More sharing options...
unistake Posted November 4, 2010 Share Posted November 4, 2010 Try this: $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } } echo " <tr> <td colspan=\"2\" style=\"font: 10px verdana,sans-serif; color: #3399AA;\">'.$m.'</td> </tr></table><br>"; flock($file, LOCK_UN); fclose($file); Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130311 Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2010 Share Posted November 4, 2010 Do a 'view source' and make sure it isn't actually there to rule out a simple formatting problem. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130314 Share on other sites More sharing options...
membot Posted November 4, 2010 Author Share Posted November 4, 2010 @Pikachu2000 Yeah, it isn't there. The source stops after the script too. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130320 Share on other sites More sharing options...
membot Posted November 4, 2010 Author Share Posted November 4, 2010 @unistake Umm, I don't think that's going to work. Why'd you take the last row of the table out of the loop? Also, you made the last echo double quotes, which will mess it all up. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130322 Share on other sites More sharing options...
membot Posted November 4, 2010 Author Share Posted November 4, 2010 I feel like my life would be a lot easier if I could see the PHP error messages, but my school server is set to not show them, and I can't change it. Grrr. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130325 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 You should be able to turn on error_reporting/display_errors in your script. You should also be developing and debugging php code on a local development system, not your school's server. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130326 Share on other sites More sharing options...
mikosiko Posted November 4, 2010 Share Posted November 4, 2010 I have a page that shows entries in a guestbook I'm making, and below the entries there is supposed to be a form to write an entry. Except, none of the HTML after the script to show the entries shows up on the page. I have no clue what's wrong. Here is the script to show the entries. $n is name, $d is date, $s is site (optional), and $m is message. $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } echo ' <tr> <td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;">'.$m.'</td> </tr></table><br> '; } flock($file, LOCK_UN); fclose($file); The file it is reading looks like this: |11:51 am, 3rd Nov 2010|Memoria|none|Hello. |11:51 am, 3rd Nov 2010|Memoria|http://sitehere|Hello again. |11:51 am, 3rd Nov 2010|Memoria|none|How are you doing? Thanks! I'm more confused ... the code that you posted works in the way it is (tested)... but ... you said: and below the entries there is supposed to be a form to write an entry. Except, none of the HTML after the script to show the entries shows up on the pag and I don't see any form.. so... how do you expect to get help?... show the code that is NOT working Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130340 Share on other sites More sharing options...
gamer-goddess Posted November 4, 2010 Share Posted November 4, 2010 IMO echo should always be in double quotes When HTML tags are paired with echo, you should use single quotes Also - you don't NEED any quotes (single or double) for HTML unless your attributes use spaces. So unless you're using a php variable that defines an attribute, I would take the quotes out altogether in the areas you know for a fact can only be changed by you (ie: the hard styles) Assuming this is what you want your Guest Book Entry to look like: Add a stylesheet. (This is just a simple style you could use. It would be better to refine it with divs and padding) Notice that I named each node in your table to correspond with your variable names. "m" is empty because it doesn't need a new style, but I added 4 separate classes in case you wanted to change the style in the future <style type=text/css> #GuestBookEntry { border: 1px solid #3399AA; width: 300px; font: verdana,sans-serif; color: #FFFFFF; } #GuestBookEntry TR { background-color: #3399AA; } .n { width: 50%; } .d { width: 50%; text-align: right; } .s { padding-bottom: 10px; } .m { } </style> Your PHP/HTML should look like this. Notice that the ONLY single quotes are wrapped around the link tag <a href=''> because there is a chance that (for whatever reason) a link could have a space in the URL. Notice that the class attributes do not use single or double quotes, because there is NO WAY a class would ever need a space. If you attempted to name a css class with spaces, it wouldn't work anyway. Colspan is the same way. There is NO WAY you could EVER write colspan=2 2 <== that would be colspan=22, in which case you would slap yourself on the forehead and say "2 2 is not a number, but 22 is" <?php ... echo "<table id=GuestBookEntry><tr>"; echo "<td class=n>".$n."</td>"; echo "<td class=d>".$d."</td>"; echo "</tr>"; if($s != "none"){ echo "<tr>"; echo "<td colspan=2 class=s><b>Site: </b><a href='".$s."'>".$s."</a></td>"; echo "</tr>"; } echo "<tr><td colspan=2 class=m>".$m."</td></tr></table>"; ... ?> I made a test page, using only the following, and it works perfectly: <style type=text/css> #GuestBookEntry { border: 1px solid #3399AA; width: 300px; font: verdana,sans-serif; color: #FFFFFF; } #GuestBookEntry TR { background-color: #3399AA; } .n { width: 50%; } .d { width: 50%; text-align: right; } .s { padding-bottom: 10px; } .m { } </style> <?php $n = "n"; $d = "d"; $s = "s"; $m = "m"; echo "<table id=GuestBookEntry><tr>"; echo "<td class=n>".$n."</td>"; echo "<td class=d>".$d."</td>"; echo "</tr>"; if($s != "none"){ echo "<tr>"; echo "<td colspan=2 class=s><b>Site: </b><a href='".$s."'>".$s."</a></td>"; echo "</tr>"; } echo "<tr><td colspan=2 class=m>".$m."</td></tr></table>"; ?> Also, every echo could be written on one line, but I wrote it out in multiple lines so you could see the difference Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130350 Share on other sites More sharing options...
jcbones Posted November 4, 2010 Share Posted November 4, 2010 IMO echo should always be in double quotes Why do you drop out of double quotes in order to splice in a variable to the echo statement. Double quotes tell the parser to parse that line, so any variables it finds will be populated. Single quotes are faster in processing as the parser doesn't even look at that line, just spits it out to the browser. Your example <?php ... echo "<table id=GuestBookEntry><tr>" . "<td class=n>$n</td>" . "<td class=d>$d</td>" . "</tr>"; if($s != "none"){ echo "<tr>" . "<td colspan=2 class=s><b>Site: </b><a href=\"$s\">$s</a></td>" . "</tr>"; } echo "<tr><td colspan=2 class=m>$m</td></tr></table>"; ... ?> Just sayin~. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130421 Share on other sites More sharing options...
membot Posted November 5, 2010 Author Share Posted November 5, 2010 Ok well... here's my whole source for the page. I don't think the quotes are the problem, but I don't know..... <title>Mem's Guestbook</title> <style> body {background: #33DDDD;} #content {background: #FFFFFF; width: 500px; font: 10px verdana,sans-serif; color: #3399AA; padding: 10px;} h1 {font: normal small-caps normal 30px georgia,serif; color: #33DDDD; text-shadow: #3399AA 1px 1px 3px} #cell {font: 10px verdana,sans-serif; color: #3399AA;} #input {font: 10px verdana,sans-serif; color: #3399AA; width: 150px; border: #3399AA 1px solid;} #submit {font: 10px verdana,sans-serif; color: #3399AA; border: #3399AA 1px solid; background: #89EBEB;} </style> <center> <div id="content"> <h1>Mem's Guestbook</h1> <!-- SCRIPT TO SHOW POSTS --> <?php $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } echo ' <tr> <td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;">'.$m.'</td> </tr></table><br> '; } flock($file, LOCK_UN); fclose($file); ?> <!-- END SCRIPT --> <br><br><div style="width: 400px; height: 1px; background: #3399AA;"></div><br> You can leave a message in the guestbook with the form below.<br> Feilds with a "*" are required.<br><br> <?php if($_GET['error'] == 1){ echo '<font color="red">You must fill in your name and your message.</font><br><br>'; } if($_GET['post'] == 1){ echo '<font color="green">Your message has been posted. Thank you!</font><br><br>'; } ?> <form action="post.php" method="post"> <table> <tr><td align="right" valign="middle" id="cell">*Name:</td><td><input id="input" type="text" name="name" maxlength="50"></td></tr> <tr><td align="right" valign="middle" id="cell">Site:</td><td><input id="input" type="text" name="site" maxlength="200"></td></tr> <tr><td align="right" valign="top" id="cell">*Message:</td><td><textarea id="input" name="msg" rows="5"></textarea></td></tr> <tr><td></td><td align="center"><input id="submit" type="submit" value="Post"></td></tr> </table> </form> </div> </center> Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130791 Share on other sites More sharing options...
membot Posted November 5, 2010 Author Share Posted November 5, 2010 You should also be developing and debugging php code on a local development system, not your school's server. Well sure, that would be nice, but I'm in a class and that's just the way it is. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130794 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 Ummm. If you are in a programming class and are expected to use a specific server and that server does not have the error_reporting/display_errors settings set up or they cannot be setup to give you the most HELP possible while learning, developing, and debugging your code, you have got to ask yourself if you are in the right class. Learning, developing, and debugging php code without the help from php's error_reporting is kind of like a blind guy driving a car on the highway. You might eventually get where you are going (produce some working code), but it is going to take you a very long time (at least 10x longer) and when you get there you will be all bloody and beat up (you will have wasted a lot of effort on just getting your code to run and with not much effort actually going into the coding.) P.S. You can install Apache/PHP/mysql on just about any personal computer/laptop that has a supported operating system. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130798 Share on other sites More sharing options...
jcbones Posted November 5, 2010 Share Posted November 5, 2010 WAMPServer is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130803 Share on other sites More sharing options...
membot Posted November 5, 2010 Author Share Posted November 5, 2010 @PFMaBiSmAd: I totally agree, but there is literally one computer class at my school (still in high school) and you get to choose what you learn. So it's not like it's specifically a PHP class, so they don't have it set up for people trying to learn PHP. I've had SO many issues with stuff also because they don't let you change permissions on things! And I could work on stuff at home, but I'd have to keep taking my files back and forth with a flash drive or something. It's a really annoying situation, but it's all I've got until I go to college. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130812 Share on other sites More sharing options...
DavidAM Posted November 5, 2010 Share Posted November 5, 2010 If you have an empty entry at the end of your file ... that is if the last line has a newline at the end of it, this line of code if(empty($entry)){exit;} is terminating your script. It will not exit the while and it will not show any HTML after the loop. An exit is an exit, quit, stop, don't do anything else. You need to break out of the while there. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130883 Share on other sites More sharing options...
membot Posted November 6, 2010 Author Share Posted November 6, 2010 @DavidAM: Thank you so much! I didn't know that exit would stop stuff after the script too. Quote Link to comment https://forums.phpfreaks.com/topic/217758-page-doesnt-show-any-html-after-a-php-script/#findComment-1130946 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.