Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP question

  • 27-11-2007 4:30pm
    #1
    Registered Users, Registered Users 2 Posts: 569 ✭✭✭


    I was wondering if anyone could help cast a quick glance over this. It's the second half of a comment page. The first half has a form that allows a user to submit a comment, and this half displays the comments.

    The top half is displaying and functioning correctly, but the bottom half of the page isn't working at all. Given that I use the same $connection variable and database labels (name, comment, email etc.) in the top half and they function, I'm almost sure that the problem isn't with them.

    When I view the source code of the page, I don't see the </table></body></html> at the end, so I'm guessing that I'm missing a ' or ; or something like that in the PHP code. The page doesn't throw up any errors either, this section just remains blank:
    <html>
    <body>
    <table width="70&#37;" border="0" align="center" cellpadding="1" cellspacing="2">
    
    <?php
    	$query = "SELECT * FROM guestbook ORDER BY autoid"; 
    	$result = mysql_query ($query, $connection);
    	
    	for ($i = 0; $i < mysql_num_rows ($result); $i++)
    	{
    	    $name = mysql_result($result, $i, "name");
    		$email = mysql_result($result, $i, "email");
    		$email_len = strinlen ($email);
    	    $comment = mysql_result($result, $i, "comment");
    	    $date = mysql_result($result, $i, "date_auto");
    		$show_date = date ("H:i:s m/d/Y", $date);
    		
    		
    		echo '
    		<tr>
    		<td width ="100%" bgcolor= "eeeeee">
    		<font face = "ariel" size = "2">';
    		if ($email_len > 0)
    		{
    			echo '<b>Name: </b> <a href="mailto:'.$email.'">'.$name.'</a>';
    		}
    		else
    		{
    			echo '<b>Name: </b>'.$name;
    		}
    		echo ' <br>
    			<b>Comments:</b>'.$comment.'
    			</font>
    			<td>
    			<td width="1%" valign="top" nowrap bgcolor ="eeeeee">
    			<font face = "arial" size = "2">
    			<b>Date: </b>'.$show_date.'
    			</font>
    			</td>
    		</tr>
    		';
    	}
    ?>
    
    </table>
    </body>
    </html>
    
    
    

    This half of the page actually starts with <table.... but I included the head and body tags as they are at the top of the page.

    Any help would be much appreciated!


Comments

  • Registered Users, Registered Users 2 Posts: 35,524 ✭✭✭✭Gordon


    Strange, I get the </table></body></html> at the end.


  • Registered Users, Registered Users 2 Posts: 569 ✭✭✭failsafe


    </snip>

    If you view the source code on that page it ends with the start of the bit i've pasted, even though all of the code i've pasted is in guestbook.php


  • Registered Users, Registered Users 2 Posts: 3,889 ✭✭✭cgarvey


    how about commenting out, or temporarily removing, some/most/all of the code between the PHP tags and put it back in slowly to narrow the problem down?


  • Registered Users, Registered Users 2 Posts: 569 ✭✭✭failsafe


    *EDIT: I found the source of my problem, I had "stinlen" as opposed to "strlen" for the string length function! cgarvey, thanks a mil for the advice, never thought of that and it helped me spot the problem. I think this tells me I need to switch from notepad to an editor with syntax highlighting!


    Thanks for the suggestion. I tried that out and found the following:

    I put <h1>Test</h1> below the php section. I could see it fine with all the php part commented out. I could see it when I started adding back several pieces until I got as far as
    <?php
    	$query = "SELECT * FROM guestbook ORDER BY date_auto"; 
    	$result = mysql_query ($query, $connection);
    	
    	for ($i = 0; $i < mysql_num_rows ($result); $i++)
    	{
    	    $name = mysql_result ($result, $i, "name");
    	    $email = mysql_result ($result, $i, "email");
    		$email_len = strinlen ($email);
    	    $comment = mysql_result ($result, $i, "comment");
    	    $date = mysql_result ($result, $i, "date_auto");
    		$show_date = date ("H:i:s m/d/Y", $date);
    		
    		
    #		echo '
    #		<tr>
    #		<td width ="100&#37;" bgcolor= "eeeeee">
    #		<font face = "ariel" size = "2">';
    #		if ($email_len > 0)
    #		{
    #			echo '<b>Name: </b> <a href="mailto:'.$email.'">'.$name.'</a>';
    #		}
    #		else
    #		{
    #			echo '<b>Name: </b>'.$name;
    #		}
    #		echo ' <br>
    #			<b>Comments:</b>'.$comment.'
    #			</font>
    #			<td>
    #			<td width="1%" valign="top" nowrap bgcolor ="eeeeee">
    #			<font face = "arial" size = "2">
    #			<b>Date: </b>'.$show_date.'
    #			</font>
    #			</td>
    #		</tr>
    #		';
    	}
    ?>
    
    <h1>Test</h1>
    

    and then it disappeared. My php skills aren't very good as I'm only starting out, should a "for" function cause a problem if there's no action linked to it, or have I potentially discovered the root of my problem?


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    At a quick glance, there are several spelling mistakes in that code, "strinlen" being a nonexistant function in PHP, "ariel" being a non-existant font on most systems, no # before the colour codes... and that's about where I stopped.

    Edit: Also you're using HTML4.0 constructs (not causing the problem but it's bad style). Your problem is probably that strinlen never resolves because it should be strlen.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    html 4.0 constructs?

    also when I'm coding in php sounds stupid but to find errors I put

    echo "pass1";
    echo "pass2";

    throughout the code to identify how far it gets!


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    Realistically, nobody should be using <FONT FACE="whatever"> on the brink of the year 2008.


Advertisement