SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot frosco's Avatar
    Join Date
    Jul 2003
    Location
    WA state
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query String ~ Need another set of eyes

    Nothing is pulling from the database here - driving me crazy! PHP not my strong point, can someone tell me what I did wrong?

    I did an echo on the "affid" to make sure it was getting the right info, and it was.

    Here's my connection info:
    Code:
    $hostname='example.secureserver.net';
    $username='user_name';
    $password='password';
    $dbname='db_name';
    
    
    mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_db($dbname);
    ...and the rest
    Code:
    $query4 = "SELECT * FROM awsd_users WHERE id=$affid";
    $result = mysql_query($query4);
    if($result) {
        while($row = mysql_fetch_array($result))
    {
            $name = $row["$name"];
            $location = $row["$location"];
            $title = $row["$title"];
            $id = $row["$id"];
            $email = $row["$email"];
                 }
    }
    Thanks!!

  2. #2
    SitePoint Zealot frosco's Avatar
    Join Date
    Jul 2003
    Location
    WA state
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind! I forgot to define variables, lol, dumb.

    Thanks!

  3. #3
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, use single quotes around the value in the query.
    Normally that wouldn't be a problem, but the way you try to access the values from the array is not right.
    PHP Code:
    $query4 "SELECT * FROM awsd_users WHERE id='$affid'";
    while(
    $row mysql_fetch_array($result)) {
        
    /*
            If you use $row["$name"] or $row[$name], that's the same.
            If you've set the variable like this for example: $name = 'myField';
            You'd get the value of $row['myField'].
            If you didn't set the variable $name first, the output would be Array()
        */
        
    $name $row['Name'];
        
    $location $row['Location'];
        
    $title $row['Title'];
        
    $id $row['id'];
        
    $email $row['Email'];

    FOR SALE: 1 set of morals, never used, will sell cheap

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey frosco you assign those values in a while loop, you do realize that if more than one record exist those values will only contain the last row values. If you only expect that query to return on record use an if statement to check for a valid result set. That way if no returned record you have a way to display an error message.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Zealot frosco's Avatar
    Join Date
    Jul 2003
    Location
    WA state
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seeing the error of my ways here, lol, thank you! I have more learning to go and do.

    Amber


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •