Caitlin-havener Posted April 10, 2011 Share Posted April 10, 2011 Can you see what is wrong with the following function? I am getting "query '' failedWarning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/students/ca081919/public_html/DIG3134/test.php on line 198It is team's turn!". It should just say"It is Black team's turn!" or "It is gold team's turn!"Line 198 is while($row=mysql_fetch_array($result)) function whosturn(){global $Login, $Password; $maxitnum=largest_itemnumber(); $connection=mysql_connect('localhost',$Login,$Password) or print 'main connect failed'; mysql_select_db('ca081919',$connection) or print "main select failed"; $g="SELECT color FROM WhosTurn WHERE turn_number=$maxitnum"; $result = mysql_query ($q, $connection) or print "query '$q' failed"; while($row=mysql_fetch_array($result)) { $team=$row[0]; } print "It is $team team's turn!"; if ($team=='gold') { $connection=mysql_connect('localhost',$Login,$Password) or print 'main connect failed'; mysql_select_db('ca081919',$connection) or print "main select failed"; $q="INSERT INTO WhosTurn VALUES (null, 'black', 'none')"; $result = mysql_query ($q, $connection) or print "query '$q' failed"; } else { $connection=mysql_connect('localhost',$Login,$Password) or print 'main connect failed'; mysql_select_db('ca081919',$connection) or print "main select failed"; $q="INSERT INTO WhosTurn VALUES (null, 'gold', 'none')"; $result = mysql_query ($q, $connection) or print "query '$q' failed"; } } # whosturn Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2011 Share Posted April 10, 2011 Have it print the error message from MySQL instead: $result = mysql_query ($q, $connection) or print mysql_error(); Link to comment Share on other sites More sharing options...
Caitlin-havener Posted April 10, 2011 Author Share Posted April 10, 2011 It says Query was emptyWarning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/students/ca081919/public_html/DIG3134/test.php on line 198It is team's turn!But its not empty!!!!table: Full Texts turn_number color pick_team Edit Delete 1 black black picked Edit Delete 2 gold gold picked Edit Delete 3 black black picked Edit Delete 4 gold gold picked Edit Delete 5 gold gold picked Edit Delete 6 black black picked Edit Delete 7 gold gold picked Edit Delete 8 black black picked Edit Delete 9 black black picked Edit Delete 10 gold gold picked Edit Delete 11 black black picked Edit Delete 12 gold gold picked Edit Delete 13 black black picked Edit Delete 14 gold gold picked Edit Delete 15 black black picked Edit Delete 16 gold gold picked Edit Delete 17 black black picked Edit Delete 18 gold none Edit Delete 19 gold none Edit Delete 20 gold none Edit Delete 21 gold none Edit Delete 22 gold none Edit Delete 23 gold none Edit Delete 24 black black picked Edit Delete 25 gold none Link to comment Share on other sites More sharing options...
jeffman Posted April 10, 2011 Share Posted April 10, 2011 $g != $q Link to comment Share on other sites More sharing options...
Caitlin-havener Posted April 10, 2011 Author Share Posted April 10, 2011 $g != $qWait what!? Not sure what you mean how do I implement that? Link to comment Share on other sites More sharing options...
birbal Posted April 10, 2011 Share Posted April 10, 2011 $g="SELECT color FROM WhosTurn WHERE turn_number=$maxitnum";$result = mysql_query ($q, $connection) or print "query '$q' failed";$result = mysql_query ($q, $connection)will be$result = mysql_query ($g, $connection) Link to comment Share on other sites More sharing options...
GerryH Posted April 10, 2011 Share Posted April 10, 2011 He means you set your query var = $q not $g.$g="SELECT color FROM WhosTurn WHERE turn_number=$maxitnum";$result = mysql_query ($q, $connection) or print "query '$q' failed"; Link to comment Share on other sites More sharing options...
Caitlin-havener Posted April 10, 2011 Author Share Posted April 10, 2011 He means you set your query var = $q not $g.$g="SELECT color FROM WhosTurn WHERE turn_number=$maxitnum";$result = mysql_query ($q, $connection) or print "query '$q' failed";omg dont know how i did that! Link to comment Share on other sites More sharing options...
GerryH Posted April 10, 2011 Share Posted April 10, 2011 Hehe! Yea single letter variables especially the letter q and g have been known to sneak up and bite ya! Link to comment Share on other sites More sharing options...
jeffman Posted April 10, 2011 Share Posted April 10, 2011 Sorry if my post was cryptic. Glad you got it figured out, though. Link to comment Share on other sites More sharing options...
Caitlin-havener Posted April 11, 2011 Author Share Posted April 11, 2011 Sorry if my post was cryptic. Glad you got it figured out, though.LoL I get the joke now! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.