Connecting Tech Pros Worldwide Help | Site Map

Error while fetching values from table containing login info

Newbie
 
Join Date: Oct 2006
Posts: 14
#1: Oct 16 '06
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 "COORDINATOR" where all 5 usernames, password (md5 protected) and short description of the departments are located.

When a volunteer is getting booked by a certain festivaldepartment, 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.php">logout</a>';


// Get ID Of Volunteer From The Previous Page

$VRIJWILLIGER_ID = $_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($query)
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($query)
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_username = mysql_query($query)
or die("Mysql Error 3");


[/php]
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Oct 16 '06

re: Error while fetching values from table containing login info


Change your statement and you'll see what the exact error is.[php] or die('Mysql Error 3: ' . mysql_error()); [/php]
Ronald :cool:
Newbie
 
Join Date: Oct 2006
Posts: 14
#3: Oct 16 '06

re: Error while fetching values from table containing login info


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/boekvrijwilliger.php on line 56"


line 56 is this line;

$location=mysql_result($result_username,$i,"omschr ijving");

(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 :)
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Oct 16 '06

re: Error while fetching values from table containing login info


How can you request column name "omschrijving" when you only select column "description"?

Ronald :cool:
Newbie
 
Join Date: Oct 2006
Posts: 14
#5: Oct 16 '06

re: Error while fetching values from table containing login info


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,"descri ption");
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Oct 16 '06

re: Error while fetching values from table containing login info


Quote:

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,"descri ption");

How about the content of the $i variable? Should start at 0, but does it??

Ronald :cool:
Newbie
 
Join Date: Oct 2006
Posts: 14
#7: Oct 16 '06

re: Error while fetching values from table containing login info


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($query);
if (!$query) {
die('Invalid query: ' . mysql_error());
}

$i=0;

$location=mysql_result($result,$i,"description");
[/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($query)
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($query);

if (!$query) {
die('Invalid query: ' . mysql_error());
}
[/php]
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#8: Oct 16 '06

re: Error while fetching values from table containing login info


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:
Newbie
 
Join Date: Oct 2006
Posts: 14
#9: Oct 16 '06

re: Error while fetching values from table containing login info


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
Newbie
 
Join Date: Oct 2006
Posts: 14
#10: Oct 16 '06

re: Error while fetching values from table containing login info


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
Reply