Error while fetching values from table containing login info

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • warezguy05
    New Member
    • Oct 2006
    • 14

    Error while fetching values from table containing login info

    Hello

    I'm experiencing a problem;

    I've written a small script where volunteers can be booked for work-activities at a festival.
    The festival has 5 different departments so i've created a database-table named "COORDINATO R" where all 5 usernames, password (md5 protected) and short description of the departments are located.

    When a volunteer is getting booked by a certain festivaldepartm ent, the earlier mentioned description of the department should be added to a SIGNUP table so its easy to see for everyone where a certain volunteer will work at the festival (behind a bar, or building the stage etc..)

    To get the right department-description, I use the username that is used at the current session.

    But...when I query the code, I get an error. The third query gives me an error ("Mysql Error 3") back but i don't see why.
    As far as I see..the code should be working :/ (I used lowercase fieldnames in the COORDINATOR table by the way)


    Part of the code;

    [php]

    <?

    // Check Login

    if($logged_in){
    echo 'Logged in as '.$_SESSION["username"].', <a href="logout.ph p">logout</a>';


    // Get ID Of Volunteer From The Previous Page

    $VRIJWILLIGER_I D = $_GET["id"];


    // Query Details Of Volunteer

    $query = "SELECT VOLUNTEER_ID, FIRSTNAME, LASTNAME, ADDRESS, ZIPCODE, CITY, TELEPHONE, AVAILABLE FROM VOLUNTEER
    where VOLUNTEER_ID = $VOLUNTEER_ID";

    $result = mysql_query($qu ery)
    or die("Mysql Error 1");


    // Query Amount Of Days That The Volunteer Is Available For Work

    $query = "SELECT DAYS FROM SIGNUP
    where VOLUNTEER_ID = $VOLUNTEER_ID";

    $result_days = mysql_query($qu ery)
    or die("Mysql Error 2");


    // Assign The Username From The Session To Loginname

    $loginname = $_SESSION["username"];


    // Get The Right Username Using The Loginname

    $query = "SELECT description FROM COORDINATOR
    where username = $loginname";

    $result_usernam e = mysql_query($qu ery)
    or die("Mysql Error 3");


    [/php]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Change your statement and you'll see what the exact error is.[php] or die('Mysql Error 3: ' . mysql_error()); [/php]
    Ronald :cool:

    Comment

    • warezguy05
      New Member
      • Oct 2006
      • 14

      #3
      okay thanks :)

      using that function i see this error;

      "Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/livesets-online.com/www/topics/boekvrijwillige r.php on line 56"


      line 56 is this line;

      $location=mysql _result($result _username,$i,"o mschrijving");

      (nothing wrong with this as far as i can see..although im only a php noob ;-) )

      the value of $location will be updated in the sign_up table so all festival-departments can see where a certain volunteer will work :)

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        How can you request column name "omschrijvi ng" when you only select column "descriptio n"?

        Ronald :cool:

        Comment

        • warezguy05
          New Member
          • Oct 2006
          • 14

          #5
          sorry, i had forgotten to translate that specific line of my script to be able to request help here :)

          i meant;

          $location=mysql _result($result _username,$i,"d escription");

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Originally posted by warezguy05
            sorry, i had forgotten to translate that specific line of my script to be able to request help here :)

            i meant;

            $location=mysql _result($result _username,$i,"d escription");
            How about the content of the $i variable? Should start at 0, but does it??

            Ronald :cool:

            Comment

            • warezguy05
              New Member
              • Oct 2006
              • 14

              #7
              till half an hour ago i hadn't read much of how it works with rows and assigning with results , but now i know a little bit more..

              i changed the code to this but still no result (and the same error-message)

              [php]

              $loginname = $_SESSION["username"];

              $query = "SELECT description FROM COORDINATOR
              where username = $loginname";


              $result = mysql_query($qu ery);
              if (!$query) {
              die('Invalid query: ' . mysql_error());
              }

              $i=0;

              $location=mysql _result($result ,$i,"descriptio n");
              [/php]

              by the way; when i look at the database, the value of location in the sign-up has been changed from NULL to blank.
              is this correct? i mean ..should the value been updated although there is no valid value assigned to $location?

              rest of the code;
              [php]

              // Set availability to NO

              $available="no" ;


              // Update the availability of the volunteer at the signup table

              $query= "UPDATE VOLUNTEER SET AVAILABLE = '$available' WHERE VOLUNTEER_ID = $VOLUNTEER_ID";
              $result = mysql_query($qu ery)
              or die("Mysql error 4");

              // Update the location where the volunteer will work

              $query= "UPDATE SIGNUP SET LOCATION = '$location' WHERE VOLUNTEER_ID = $VOLUNTEER_ID";
              $result = mysql_query($qu ery);

              if (!$query) {
              die('Invalid query: ' . mysql_error());
              }
              [/php]

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                You must not check $query, because that is just the SQL statement variable. You should test the result of the mysql_query command, so
                [php]if (!$result) {[/php]

                If $location variable containsed a blank your row was updated with that blank.

                Ronald :cool:

                Comment

                • warezguy05
                  New Member
                  • Oct 2006
                  • 14

                  #9
                  if (!$result) { echo "blablabla" ;
                  }

                  and it echoes blablabla so something must be wrong than regarding the selection statement.
                  lets see if i can figure out what

                  Comment

                  • warezguy05
                    New Member
                    • Oct 2006
                    • 14

                    #10
                    i finally figured it out;

                    query had to be;

                    $query = "SELECT description FROM COORDINATOR
                    where username = '$loginname'";

                    instead of

                    $query = "SELECT description FROM COORDINATOR
                    where username = $loginname";

                    (notice the single quotes)
                    i didn't know i had to use them...anyway.. .maybe till soon when i have a new question :p

                    Comment

                    Working...