PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 3rd, 2003, 08:23 PM
Tiger in a Tube Tiger in a Tube is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne
Posts: 5 Tiger in a Tube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
passing variables around several php pages

Hi there,

I have a user authentication set up that then (is supposed) to use the username to provide specific content (in this case a welcome message) per user.

The mechanic is you log in, are validated using a mySQL database. You then go to the main page where a message stored as part of your mySQL record is displayed.

My problem is that I can't get the record to display. $username is the name of the variable through my pages.

I'm using frames. The query code is;
PHP Code:
function print_message($username)
{
    
$conn=db_connect();

    
$query "select * from content_admin where username='$username'";
    
$message mysql_query($query$conn);
    
$use mysql_fetch_row($message);
    return 
$use[4];


The print_message($username) function is called from this piece of code.


PHP Code:
 print_r($username); //for checking what's coming out of the query
$use print_message($username);

session_start();
check_valid_user();

?>
<HTML>
//irrelevant HTML here

<TABLE WIDTH=136 BORDER=0 CELLPADDING=0 CELLSPACING=0>
    <TR>

    <TD WIDTH=136 HEIGHT=152 align="left" valign="top" background="images/home_right01.gif" class="content" ALT="">
      <font size="1"></font>
      <table width="88%" border="0" align="center" cellpadding="1" cellspacing="0">
        <tr>
          <td height="129"><font size="1" face="Trebuchet MS"> <br>
            <?=$use ?></font></td>
        </tr>
      </table> 

The result of this is that I can't get the message to display. I'm assuming that the problem is to do with passing the $username because when I put a hard coded user name, I get the correct message.

thanks in advance for your help,
TiaT

Reply With Quote
  #2  
Old July 3rd, 2003, 09:12 PM
DudeThatWasRude DudeThatWasRude is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 7 DudeThatWasRude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
$query = "select * from content_admin where username='$username'";


This is not good coding style.
Select * from.....
will never guarantee you that some field will appear in the specific posion.

An example of better code for your context:

<?php
mysql_connect($host, $user, $password);
mysql_select_db("database");
$result = mysql_query("select user_id, fullname from table");
while ($row = mysql_fetch_array($result)) {
echo "user_id: ".$row["user_id"]."<br>\n";
echo "user_id: ".$row[0]."<br>\n";
.....
.....

Reply With Quote
  #3  
Old July 3rd, 2003, 10:24 PM
Tiger in a Tube Tiger in a Tube is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne
Posts: 5 Tiger in a Tube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks Dude, I'll change that query accordingly.

It still doesn't solve my problem though. .

Reply With Quote
  #4  
Old July 4th, 2003, 04:44 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Looks like you are trying to pass an array to a function that is looking for a string:

PHP Code:
 print_r($username); //for checking what's coming out of the query
$use print_message($username); 
I'm not sure of how you structured your $username array (you should have posted the info from 'print_r'), however, I assume you could call your function like this:
PHP Code:
 $use print_message($username[0]); 
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #5  
Old July 4th, 2003, 09:35 PM
Tiger in a Tube Tiger in a Tube is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne
Posts: 5 Tiger in a Tube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yes, I've fixed that so it gives the right record out of the array.

I don't actually get any value or result from the print_r($username[0]) funtion, so I can't post it.

But the problem still remains that I can't get the appropriate value to come up when I use the variable. If I hard code the the username in to the query, I get a result.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > passing variables around several php pages


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT