Page 1 of 1

echo not working?

Posted: Thu Jun 12, 2003 1:59 pm
by m3rajk
obviously this ins't the place to seek javascript help so i'm looking elsewhere to get the javascript of the last thing i was asking about working... but in the mena time i've moved on to other basic pages.. trying to get the main profile page up, i tried rtesting it without the iframe pages, but.. the $un variable isn't being passed for some reason. i can tell because i had pics for a dummy profile and instead i'm getting what i made intot he default image.

Code: Select all

<?php

/* ***************************************************
   ** set any and all variables that need to be set **
   *************************************************** */

$un=$_GET['un'];

/* *****************************
   ** call to (the ) database **
   ***************************** */

/* *******************************************************
   ** find where we are and call the creation functions **
   ******************************************************* */

if(isset($un)){
  //  if($check){ // user exists
    bgnpg(); pb();
    //}else{ // user doesn't exist
    //bgnpg(); nu();
    //}
}else{ // no user specified
  home();
}

/* *********************************
   ** create the appropriate page **
   ********************************* */

function bgnpg(){  # create the BeGiNing of each PaGe 
  ?><html>
       <head>
         <title>MySite -- <?php echo "$un"; ?>'s User Profile</title>
         <meta name="Author" content="coded by: Josh Perlmutter; images by Morgan O'Brien-Bledsow & Tamara Collette all rights reserved">
         <style type="text/css">
           <!-- this comment is for non-css compliant browsers
           {text-decoration=none}
           end of css -->
	 </style>
       </head>
       <body bgcolor="#000000" text="#c8c8c8" alink="#fc00ff" vlink="#00e0c4" link="#ffffff">
       <center><p>&nbsp;</p>
 <?php
}
function pb(){
  ?><!-- profile body -->
       <table frame="void" bgcolor="#000000" text="#c8c8c8" border="0"; cellspacing="0" cellpadding="0">
       <tr><!-- row 1: user stats and pics -->
         <td width="750" height="450" colspan="2"><!-- table to align top row -->
	   <table frame="void" bgcolor="#000000" text="#c8c8c8" border="0"; cellspacing="0" cellpadding="0">
             <tr><td width="300" height="450">
	         <iframe frameborder="0" name="stats" height="450" width="300" src="stats.php?un=<?php echo "$un"; ?>">if you see this, upgrade to <a href="http://www.mozilla.org/">Mozilla</a> 1.3.1 or later</iframe>
               </td><td width="450" height="450"><!-- inner table for pictures -->
                 <table frame="void" bgcolor="#000000" border="0"; cellspacing="0" cellpadding="0">
	           <tr><!-- row 1: main pic, thumbs 1 and 2 -->
                     <td height="300" width="300" colspan="2">
  <?php
    echo "\t\t\t<a href="userpics/m.$un.jpg" target="pic"><img src="thumb.php?pic=userpics/m.$un.jpg&fn=main" border="0"></a>\n";
  ?>
                     </td><td height="300" width="150">
                     <!-- table for thumbs 1 and 2 -->
                     <table frame="void" bgcolor="#000000" border="0"; cellspacing="0" cellpadding="0">
                       <tr><td height="150" width="150">
                         <a href="<?php echo 'userpics/t1.'.$un.'.jpg'; ?>" target="pic"><img src="thumb.php?pic=<?php echo 'userpics/t1.'.$un.'.jpg'; ?>&fn=thumb" border="0"></a>
                       </td></tr><tr><td height="150" width="150">
                         <a href="<?php echo 'userpics/t2.'.$un.'.jpg'; ?>" target="pic"><img src="thumb.php?pic=<?php echo 'userpics/t2.'.$un.'.jpg'; ?>&fn=thumb" border="0"></a>
                       </td></tr>
                     </table><!-- end table for thumbs 1 and 2 -->
                   </td>
                 </tr><tr><!-- row 2: thums 3 and 4 and salute -->
                   <td height="150" width="150">
                     <a href="<?php echo 'userpics/t3.'.$un.'.jpg'; ?>" target="pic"><img src="thumb.php?pic=<?php echo 'userpics/t3.'.$un.'.jpg'; ?>&fn=thumb" border="0"></a>
                   </td><td height="150" width="150">
                     <a href="<?php echo 'userpics/t4.'.$un.'.jpg'; ?>" target="pic"><img src="thumb.php?pic=<?php echo 'userpics/t4.'.$un.'.jpg'; ?>&fn=thumb" border="0"></a>
                   </td><td height="150" width="150">
                     <a href="<?php echo 'userpics/salute.'.$un.'.jpg'; ?>" target="pic"><img src="thumb.php?pic=<?php echo 'userpics/salute.'.$un.'.jpg'; ?>&fn=thumb" border="0"></a>
                   </td>
                 </tr>
               </table><!-- end table for pictures -->
             </td></tr>
           </table><!-- end table for row 1 -->
         </td>
       </tr><tr><!-- row2: comments and lust links -->
	 <td height="10" width="550" align="center">View <a name="#comments" href="#comments" onClick="window.open('comments.php?un=<?php echo "$un"; ?>', 'comments', 'height=250,width=500,scrolling=yes');">Comments</a> for <?php echo "$un"; ?></td>
	 <td height="10" width="200" align="center">View <a name="#lust" href="#lust" onClick="window.open('lust.php?un=<?php echo "$un"; ?>', 'lust', 'height=200,width=482,scrolling=yes');">Lust List</a> for <?php echo "$un"; ?></td>
       </tr><tr><!-- row3: bio and desired list -->
         <td height="200" width="550">
           <iframe frameborder="0" name="bio" height="200" width="550" src="bio.php?un=<?php echo "$un"; ?>">if you see this, upgrade to <a href="http://www.mozilla.org/">Mozilla</a> 1.3.1 or later</iframe>
         </td><td height="200" width="200">
           <iframe frameborder="0" name="desire" height="200" width="200" src="desire.php?un=<?php echo "$un"; ?>">if you see this, upgrade to <a href="http://www.mozilla.org/">Mozilla</a> 1.3.1 or later</iframe>
         </td>
       </tr>
     </table><!-- end main profile body -->
 <?php 
}
function nu(){
  echo "<h1>There was no user found with the name $un</h1></center></body></html>";
}
function home(){
  ?><html><head>
       <title>MySite -- going home...</title>
       <meta name="Author" content="coded by: Josh Perlmutter; images by Morgan O'Brien-Bledsow & Tamara Collette all rights reserved">
       <meta http-equiv="refresh" content="0;url=index.php">
       <style type="text/css">
       <!-- this comment is for non-css compliant browsers
	 {text-decoration=none}
  end of css -->
    </style>
    </head>
    <body bgcolor="#000000" text="#c8c8c8" alink="#fc00ff" vlink="#00e0c4" link="#ffffff">
    <center>
    <p>&nbsp;</p>
    <h1>If your browser doesn't forward you, then click<a href="index.html">HERE</a> to continue</h1>
    </center></body></html>
 <?php
}
?>
all the pics are coming up waht i thought they would with one small little thing.. $un isn't being made intot he passed username like i thought it would.

does anyone know why? could you explain it to me so i can figure out how to fix it?


edit: as i wait for a response, i'm going to start on the pages for the iframes... in the meantime, here's a link to the dummy one: http://people.brandeis.edu/~m3rajk/JMT/ ... hp?un=user

Posted: Thu Jun 12, 2003 2:00 pm
by nielsene
Well you aren't passing $un to the functions, and it hasn't been declared global within the functions. Therefore the functions think $un is an undeclared variable and treat it as a null string.

Posted: Thu Jun 12, 2003 2:23 pm
by m3rajk
nielsene wrote:Well you aren't passing $un to the functions, and it hasn't been declared global within the functions. Therefore the functions think $un is an undeclared variable and treat it as a null string.
how do i declare it global within the functions?

Posted: Thu Jun 12, 2003 2:32 pm
by nielsene
1. In case you din't know. using globals instead of passing variables to functions tends to be considered poor programming practice.

2. Use the global keyword

Code: Select all

function bgnpg()
  global $un;
 ...
I would recommend doing this instead however

Code: Select all

function bgnpg($un)
...
and then changing your call to bgnph appropriately....

Posted: Thu Jun 12, 2003 2:35 pm
by m3rajk
when i learned prgramming i learned java and c concurently. i'm used to anything called outsid of functions being global and anything else being passed by variables. never liked making things global from within a function, so i'll defintely be taking the second. it's nice to know that php doesn't pass things to functions that are called outside of it.

btw: i notice you have aim. do you use it much? would it be ok if i add you to mine? it would be nice to have someone that knows this on my list.

Posted: Thu Jun 12, 2003 2:44 pm
by nielsene
I almost never use AIM, but feel free to add me and write when I'm on....