SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Arrays

  1. #1
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why does this not work?
    ...
    ...
    //$idnum is passed from another page

    $data = mysql_query("SELECT TUID, firstname, lastname, email FROM usersdata WHERE TUID=$idnum ", $dbcnx );
    $row = mysql_fetch_array($result);

    print $row["firstname"];


    Thanks

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line
    $row = mysql_fetch_array($result);
    should be
    $row = mysql_fetch_array($data);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake... I meant for those to be the same... try this example which still doesn't work.

    //$uname is passed from another spot

    $data = "SELECT ID from timeusers where usersname=$uname";
    $therow = mysql_fetch_array($data);

    ^ ^ this line is the one that MySQL give me an error on
    :Warning: 0 is not a MySQL result index in /usr/local/httpd/htdocs/timeadmin.php3 on line 44

    Here is the code

    ===
    // These variables are passed from a POST

    $sql = "INSERT INTO timeusers SET username='$uname', password='$password', transport='$transport'";

    if (mysql_query($sql)) {

    echo("User has been added successfully to table: TIMEUSERS.");
    }
    else { echo("<P>An error has occurred while trying to save changes: " . mysql_error() . "</P>" );
    }


    $data = "SELECT ID from timeusers where usersname=$uname";
    $therow = mysql_fetch_array($data);
    $tuid = $therow["ID"];
    $sql2 = "INSERT INTO usersdata SET TUID='$tuid', firstname='$fname', lastname='$lname', email='$email'";
    if (mysql_query($sql2)) {

    echo("User has been added successfully to table: USERSDATA." );
    }
    else {
    echo("<P>An error has occurred while trying to save changes: " . mysql_error() . "</P>" );
    }
    }

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couple of things
    First the query never gets run and you need single quotes around $uname since its not a number. Add this into your existing code

    $data = mysql_query("SELECT ID from timeusers where usersname='$uname'");
    $therow = mysql_fetch_array($data);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it...Thanks.


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
  •