PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,131 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,047 people online right now. Registration is fast and FREE... Join Now!




Variable not echoing

 

Variable not echoing

antiturncoat

19 Sep, 2007 - 05:22 PM
Post #1

D.I.C Head
**

Joined: 8 Aug, 2007
Posts: 98


My Contributions
hi I cant echo the username on this

CODE


<table border="0" cellpadding="0" cellspacing="0" width="159" background="images/fon_left02.gif">
<tr>
    <td width="159" height="26" background="images/left01.gif"><p class="title">Welcome<?php echo $username ?> </p> </td>
</tr>



This post has been edited by hotsnoj: 19 Sep, 2007 - 07:36 PM

User is offlineProfile CardPM
+Quote Post


skyhawk133

RE: Variable Not Echoing

19 Sep, 2007 - 05:31 PM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 16,883



Thanked: 156 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Are you getting an error?

You've got 91 posts here... you should know by now how to get answers. Post the error, or problem you're having. Post all the code. Where is $username coming from?


User is online!Profile CardPM
+Quote Post

antiturncoat

RE: Variable Not Echoing

19 Sep, 2007 - 05:33 PM
Post #3

D.I.C Head
**

Joined: 8 Aug, 2007
Posts: 98


My Contributions
there's no error but i cant echo it on the page...
User is offlineProfile CardPM
+Quote Post

William_Wilson

RE: Variable Not Echoing

19 Sep, 2007 - 05:36 PM
Post #4

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,668



Thanked: 97 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
this will only work if your code in the head section is:

CODE

<?php
//code
$username;
//more code
?>


if the variable $username is located in a function or class, it is not accessible directly to the html. I actually had this issue yesterday smile.gif
User is offlineProfile CardPM
+Quote Post

antiturncoat

RE: Variable Not Echoing

19 Sep, 2007 - 05:47 PM
Post #5

D.I.C Head
**

Joined: 8 Aug, 2007
Posts: 98


My Contributions
yeah i am having a hard time also in echoing it when it is inside a class..
I tried what you gave me but it still doesn't show.. I'll post the whole code so that it would me more clear

CODE


<?php

ob_start();
session_start();
include'connect.php';

    $username = $_SESSION['username'];
    $cid = $_SESSION['cid'];
    
        $query1 = "SELECT * FROM customer WHERE cid = '$cid' ";
        $result1 = mysql_query($query1) or die(mysql_error());
        
        while($row = mysql_fetch_assoc($result1))
        {
            $fname = $row['fname'];
            $lname = $row['lname'];
        }


ob_end_flush();
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>View Account</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <style type="text/css">
<!--
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; }
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #000000;
    font-style: italic;
    font-weight: bold;
}
-->
    </style>
</head>

<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#E6E6E6" backgrou"images/fon.gif">

<table border="0" cellpadding="0" cellspacing="0" width="100%" background="images/fon_top.gif" height="147">
<tr>
    <td align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="740">
<tr>
    <td valign="top" height="68"><img src="images/logo_top.gif" width="234" height="63" alt="" border="0"></td>
</tr>
<tr>
    <td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><a href=""><img src="images/bo1.gif" width="83" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b02.gif" width="95" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b03.gif" width="71" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b04.gif" width="91" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b05.gif" width="95" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b06.gif" width="107" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b07.gif" width="89" height="42" alt="" border="0"></a></td>
    <td><a href=""><img src="images/b08.gif" width="109" height="42" alt="" border="0"></a></td>
</tr>
</table>
    </td>
</tr>
<tr>
    <td background="images/fon_top02.gif" width="740" height="37" alt="" border="0" align="right">
<table border="0" cellpadding="5" cellspacing="0" background="">
<tr>
<td width="350" align="center">
    
    </td>
    <td width="175"><a href=""><img src="images/b_vcart.gif" width="139" height="20" alt="" border="0"></a></td>
</tr>
</table>
    </td>
</tr>
</table>
    </td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="740" align="center">
<tr valign="top">
    <td width="159" rowspan="3">
<br>



<table border="0" cellpadding="0" cellspacing="0" width="159" background="images/fon_left02.gif">
<tr>
    <td width="159" height="26" background="images/left01.gif"><p class="title">Welcome <? echo $username; ?> </p></td>
</tr>

<tr>
<td><p class="b01"><img src="images/e02.gif" width="6" height="5" alt="" border="0" align="absmiddle">&nbsp;View Account </p>
<div align="center"><img src="images/hr01.gif" width="137" height="3" alt="" border="0"></div>
<p class="b01"><img src="images/e02.gif" width="6" height="5" alt="" border="0" align="absmiddle">&nbsp;View Purchases </p>
<div align="center"><img src="images/hr01.gif" width="137" height="3" alt="" border="0"></div>
<p class="b01"><img src="images/e02.gif" width="6" height="5" alt="" border="0" align="absmiddle">&nbsp;<a href="">View Reservation </a></p>
<div align="center"><img src="images/hr01.gif" width="137" height="3" alt="" border="0"></div>
<p class="b01"><img src="images/e02.gif" width="6" height="5" alt="" border="0" align="absmiddle">&nbsp;<a href="Logout.php">Logout</a></p>
<div align="center"><img src="images/hr01.gif" width="137" height="3" alt="" border="0"></div>
</td>
</tr>
<tr>
    <td><img src="images/left_bot02.gif" alt="" width="159" height="17" border="0"></td>
</tr>
</table>
    </td>
    <td><img src="images/m11.gif" width="1" height="16" alt="" border="0"></td>
    <td><img src="images/m12.gif" width="579" height="16" alt="" border="0"></td>
    <td><img src="images/m13.gif" width="1" height="16" alt="" border="0"></td>
</tr>
<tr>
    <td bgcolor="#979797"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td>
    <td bgcolor="#FFFFFF" width="579">
<table width="90%" height="277"  border="0" align="center" cellpadding="3" cellspacing="0" id="body">
  <tr>
    <td colspan="2" class="style5">PERSONAL DETAILS
        <label></label></td>
  </tr>
  <tr>
    <td width="30%" class="text2"><div align="right" class="style4">First Name :&nbsp;&nbsp;</div></td>
    <td width="41%"><span class="style4">&nbsp;&nbsp;&nbsp;<? echo $fname; ?> </span></td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">Last Name :&nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<? echo '$lname' ?> </span> </td>
  </tr>
  <tr>
    <td colspan="2" class="style5">ADDRESS</td>
    <td width="29%">&nbsp;</td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">Street: &nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $street ?></span> </td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">City: &nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $city ?></span> </td>
    <? if($problemcity)
           {                  
              echo '<td align="left"><font color="red" size="1">*Required.</font></td>';
         }
        elseif(!empty($city))
         {
             echo '<td align="left"><font color="blue" size="1">OK.</font></td>';
         }
         ?>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">State/Province: &nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $state ?></span> </td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">Zipcode: &nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $zipcode ?></span> </td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">Country: &nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $country ?></span></td>
  </tr>
  <tr>
    <td colspan="2" class="style5">CONTACT INFORMATION </td>
    <td>&nbsp;</td>
  </tr>
  <td class="text2"><div align="right" class="style4">Email Address :&nbsp;&nbsp;</div></td>
      <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $email ?></span> </td>
  </tr>
  <tr>
    <td class="text2"><div align="right" class="style4">Contact Number :&nbsp;&nbsp;</div></td>
    <td><span class="style4">&nbsp;&nbsp;&nbsp;<?php echo $phone ?></span> </td>
  </tr>
  <tr>
    <td height="15" colspan="2" class="style5">LOGIN INFORMATION
      <label></label></td>
  </tr>
  <tr>
    <td height="15" class="style4"><div align="right">Username :&nbsp;&nbsp; </div></td>
    <td class="style4">&nbsp;&nbsp;&nbsp;<?php echo $username ?> </td>
  </tr>
  <tr>
    <td height="15" class="style4"><div align="right">Customer ID: </div></td>
    <td class="style4">&nbsp;&nbsp;&nbsp;<?php echo $cid ?></td>
  </tr>
</table>
<p class="px5"></td>
    <td bgcolor="#979797"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr>
<tr>
    <td><img src="images/m31.gif" width="1" height="16" alt="" border="0"></td>
    <td><img src="images/m32.gif" width="579" height="16" alt="" border="0"></td>
    <td><img src="images/m33.gif" width="1" height="16" alt="" border="0"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="740" align="center">
<tr>
    <td height="38" align="right" background="images/bot.gif">
<table border="0" cellpadding="0" cellspacing="0" width="570" background="">
<tr>
    <td>
<p class="menu02" align="center">
<a href="">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">About Us</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">Support</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">Services</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">Contacts</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">Help</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="">FAQ</a>
</p>
    </td>
</tr>
</table>
    </td>
</tr>
<tr>
    <td><p align="right" style="margin-right: 200px;">Copyright &copy;2003 CompanyName.com</p></td>
</tr>
</table>

</body>
</html>


This post has been edited by antiturncoat: 19 Sep, 2007 - 05:49 PM
User is offlineProfile CardPM
+Quote Post

antiturncoat

RE: Variable Not Echoing

19 Sep, 2007 - 07:23 PM
Post #6

D.I.C Head
**

Joined: 8 Aug, 2007
Posts: 98


My Contributions
bump!
User is offlineProfile CardPM
+Quote Post

snoj

RE: Variable Not Echoing

19 Sep, 2007 - 07:35 PM
Post #7

Now with 10% more nom!
Group Icon

Joined: 31 Mar, 2003
Posts: 3,388



Thanked: 31 times
Dream Kudos: 775
My Contributions
Moving to PHP and there is no need to post a "Bump". Someone will help you if they can.
User is offlineProfile CardPM
+Quote Post

Mike007

RE: Variable Not Echoing

22 Sep, 2007 - 10:46 AM
Post #8

D.I.C Regular
Group Icon

Joined: 30 Aug, 2007
Posts: 306



Thanked: 5 times
Dream Kudos: 75
My Contributions
Ok as far as i can see you don't have any problems with scope of variable being overwritten by another variable with the same name. Therefore, I think your problem is with the session. To check this simply comment out the line where you assgin the username, and instead try to assgin something else to it, like $username = "NAME". Run the script again and if it prints NAME, you'll have to go and look for the problem in your connect.php file probably.
User is offlineProfile CardPM
+Quote Post

antiturncoat

RE: Variable Not Echoing

22 Sep, 2007 - 02:25 PM
Post #9

D.I.C Head
**

Joined: 8 Aug, 2007
Posts: 98


My Contributions
well here's my connect.php

CODE

<?php

mysql_connect("localhost","root");
mysql_select_db('SoftlandiaDB') or die(mysql_error());
?>

User is offlineProfile CardPM
+Quote Post

nav33n

RE: Variable Not Echoing

3 Oct, 2007 - 01:17 AM
Post #10

D.I.C Head
**

Joined: 2 Oct, 2007
Posts: 71



Thanked: 6 times
My Contributions
i believe, $username = $_SESSION['username']; is returning null. So its not printing anything. First print what is in $_SESSION['username'].
User is offlineProfile CardPM
+Quote Post

_net

RE: Variable Not Echoing

4 Oct, 2007 - 06:01 PM
Post #11

D.I.C Head
**

Joined: 22 Sep, 2007
Posts: 146



Thanked: 1 times
My Contributions
Try this in your code.

CODE

if (isset($username) && ($username != "")) {
     echo "Username is: ".$username;
} else {
   echo "Username is not set!";
}

User is offlineProfile CardPM
+Quote Post

blux

RE: Variable Not Echoing

5 Oct, 2007 - 08:38 AM
Post #12

New D.I.C Head
*

Joined: 7 Aug, 2007
Posts: 22


My Contributions
Try echoing the cid var.

Maybe the problem is on the page that you set the session var username. You must put the session_start EVERYWHERE you need to use the session vars (this include when you set them)...

This post has been edited by blux: 5 Oct, 2007 - 08:48 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:39PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month