Jump to content

Php Problem


kaz
 Share

Recommended Posts

I dont get this. I have the following PHP code on my (home.php) page.

 

><?php
if ($bbuserinfo['userid']!=0) { 
$username=$bbuserinfo['username']; 
echo("
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
 <tr>
   <td width='100%'><a href='forum/private.php?'>Private Messages</a> |
   <a href='forum/forumdisplay.php?f=128'>Forum Announcements</a> |
   <a href='forum/search.php?do=getnew'>New Posts</a> |
   <a href='forum/login.php?do=logout'>Logout</a></td>
 </tr>
 <tr>
   <td width='100%'><align='center'><span class='sectionheader'>Welcome back, $username!<br></td>
   </tr>
                       </table>
 ");
} else { 
   
("
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
 <tr>
   <td width='100%'><a href='forum/private.php?'>Private Messages</a> |
   <a href='forum/forumdisplay.php?f=128'>Forum Announcements</a> |
   <a href='forum/search.php?do=getnew'>New Posts</a> |
   <a href='forum/login.php?do=logout'>Logout</a></td>
 </tr>
 <tr>
   <td width='100%'>Please login or click here to <a href='forum/register.php?'>register</a> for free 
<form action='/forum/login.php' method='post' onsubmit='md5hash(vb_login_password,vb_login_md5password)'> 
       <script type='text/javascript' src='/forum/clientscript/vbulletin_md5.js'></script> 
        
        <span class='sectionheader'>Username:</span> 
           <input type='text' class='button' name='vb_login_username' id='navbar_username' size='15' accesskey='u' tabindex='1' value='' onfocus='if (this.value == 'username') this.value = '';' /><br> 
            
           <span class='sectionheader'>Password: </span> 
           <input type='password' class='button' name='vb_login_password' size='15' accesskey='p' tabindex='2' /><br> 
           <input type='checkbox' name='cookieuser' value='1' tabindex='3' id='cb_cookieuser_navbar' accesskey='c' checked='checked' /><span class='sectionheader'>Remember Me</span><br> 
        
        
        
       <input name='submit' type='submit' class='button' accesskey='s' tabindex='4' title='Log In' value='Log In' /> 
       <input type='hidden' name='do' value='login' /> 
       <input type='hidden' name='forceredirect' value='1' />             
       <input type='hidden' name='vb_login_md5password' /> 
       </form> 
                       </span> </td>
                       </tr>
                       </table>                        
                       "); ?>
                       <? 

} 

?>

 

However this code appears to do nothing it just shows blank :eek:

Link to comment
Share on other sites

The echo command just looks like:

 

echo "Hello world";

 

But on your page, it's set up as echo("Hello World"); (although with the two groups of HTML text).

 

So the parenthesis you have for it aren't needed.

 

Also, in the second part of the code after:

 

} else {

 

you don't have any sort of command, just a parenthesis and all the HTML text. You need to add an echo command in that half as well. It should look like:

 

<?php

if ($bbuserinfo['userid']!=0) {

$username=$bbuserinfo['username'];

echo "

[all your HTML text]

";

} else {

echo "

[all your HTML text]

";

}

?>

Link to comment
Share on other sites

Hi that worked but I get a error this is the code i used

 

><?php
if ($bbuserinfo['userid']!=0) {
$username=$bbuserinfo['username'];
echo "
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
 <tr>
   <td width='100%'><align='center'><span class='sectionheader'>Welcome back, $username!<br>
   <a href='forum/search.php?do=getnew'>New Posts</a><br>
   <a href='forum/login.php?do=logout'>Logout</a> Click <a href="/forum/?">here</a> to go to the forums or continue to browse at your ease
   </td>
 </tr>
 <tr>
   <td width='100%'></td>
   </tr>
                       </table>

";
} else {
echo "
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
 <tr>
   <td width='100%'>Welcome Guest, Please <a href='forum/register.php?'>register</a> for free 
<form action='/forum/login.php' method='post' onsubmit='md5hash(vb_login_password,vb_login_md5password)'> 
       <script type='text/javascript' src='/forum/clientscript/vbulletin_md5.js'></script> 
                 <span class='sectionheader'>Username:</span><br> 
           <input type='text' class='button' name='vb_login_username' id='navbar_username' size='10' accesskey='u' tabindex='1' value='' onfocus='if (this.value == 'username') this.value = '';' /><br> 
            
           <span class='sectionheader'>Password:</span><br> 
           <input type='password' class='button' name='vb_login_password' size='10' accesskey='p' tabindex='2' /><br> 
        <input name='submit' type='submit' class='button' accesskey='s' tabindex='4' title='Log In' value='Log In' /> 
       <input type='hidden' name='do' value='login' /> 
       <input type='hidden' name='forceredirect' value='1' />             
       <input type='hidden' name='vb_login_md5password' /> 
       </form> 
                       </span> </td>
                       </tr>
                       </table>";
}
?>

 

I get this error :whip:

 

Warning: Division by zero in /home/deathea/public_html/home.php on line 159

 

Warning: Division by zero in /home/deathea/public_html/home.php on line 167

 

The line 159 reads

 

>";

 

Its right before the else command

Link to comment
Share on other sites

I believe you're seeing that error because you have unescaped quotes in the echo() string:

>  <a href='forum/login.php?do=logout'>Logout</a> Click <a href="/forum/?">here</a> to go to the forums or continue to browse at your ease

The quotes in the second href attribute need to be escaped as \" (or replaced with single quotes as you have in the first href attribute):

>  <a href='forum/login.php?do=logout'>Logout</a> Click <a href=\"/forum/?\">here</a> to go to the forums or continue to browse at your ease

Link to comment
Share on other sites

Kaz, another way to code this is to use

HEREDOC to print

preserving spaces and mixing html and both quotes and even php variables.

follow the echo or print tag with <<< and then a delimiter like HEREDOC

using

><?php
if ($bbuserinfo['userid']!=0) { 
$username=$bbuserinfo['username']; 
print <<< HERDOC
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
<tr>
  <td width='100%'><a href='forum/private.php?'>Private Messages</a> |
  <a href='forum/forumdisplay.php?f=128'>Forum Announcements</a> |
  <a href='forum/search.php?do=getnew'>New Posts</a> |
  <a href='forum/login.php?do=logout'>Logout</a></td>
</tr>
<tr>
  <td width='100%'><align='center'><span class='sectionheader'>Welcome back, $username!<br></td>
  </tr>
</table>
HERDOC;

} else { 
  
print <<< HEREDOC
<table border='0' cellpadding='0' cellspacing='0' width='100%' >
<tr>
  <td width='100%'><a href='forum/private.php?'>Private Messages</a> |
  <a href='forum/forumdisplay.php?f=128'>Forum Announcements</a> |
  <a href='forum/search.php?do=getnew'>New Posts</a> |
  <a href='forum/login.php?do=logout'>Logout</a></td>
</tr>
<tr>
  <td width='100%'>Please login or click here to <a href='forum/register.php?'>register</a> for free 
<form action='/forum/login.php' method='post' onsubmit='md5hash(vb_login_password,vb_login_md5password)'> 
      <script type='text/javascript' src='/forum/clientscript/vbulletin_md5.js'></script> 
       
       <span class='sectionheader'>Username:</span> 
          <input type='text' class='button' name='vb_login_username' id='navbar_username' size='15' accesskey='u' tabindex='1' value='' onfocus='if (this.value == 'username') this.value = '';' /><br> 
           
          <span class='sectionheader'>Password: </span> 
          <input type='password' class='button' name='vb_login_password' size='15' accesskey='p' tabindex='2' /><br> 
          <input type='checkbox' name='cookieuser' value='1' tabindex='3' id='cb_cookieuser_navbar' accesskey='c' checked='checked' /><span class='sectionheader'>Remember Me</span><br> 
       
       
       
      <input name='submit' type='submit' class='button' accesskey='s' tabindex='4' title='Log In' value='Log In' /> 
      <input type='hidden' name='do' value='login' /> 
      <input type='hidden' name='forceredirect' value='1' />             
      <input type='hidden' name='vb_login_md5password' /> 
      </form> 
                      </span> </td>
                      </tr>
                      </table>                        
HEREDOC;
} 

?>

Link to comment
Share on other sites

The HEREDOC way is fine however in Dreamweaver, you just get the PHP icon in the WYSIWYG view which makes is less friendly to edit the html as you have to now use code view.

 

So I now do the following and it works very well.

 

<?PHP if(condition){ ?>

 

 

A BUNCH OF HTML GOES HERE WITH OR WITHOUT PHP EMBEDDED

 

 

<?PHP } ?>

 

Only if the condition is true will the html be rendered. You see all the HTML in Dreamweaver's WYSIWYG view so it is very easy to maintain.

 

Of course you can also replace

<?PHP } ?>

 

with

 

<?PHP } else { ?>

 

MORE HTML

 

<?PHP } ?>

 

AND SO ON

 

 

Wayne

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...