Aaron4osu Posted February 2, 2012 Share Posted February 2, 2012 I'm getting the following error after running a query when I run mysql_fetch_array(): Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in public_html/pitchShark2/Poll/inc/functions.php on line 24 Any help will be greatly Line 24 is: while($row = mysql_fetch_array($result)) // app_config.php defines: DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD <?php require_once '../scripts/app_config.php'; require_once '../scripts/database_connection.php'; //require("db.php"); //GETTING VARIABLES START if (isset($_POST['action'])) { $action = mysql_real_escape_string($_POST['action']); } if (isset($_POST['pollAnswerID'])) { $pollAnswerID = mysql_real_escape_string($_POST['pollAnswerID']); } //GETTING VARIABLES END function getPoll($pollID){ $query = "SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC"; $result = mysql_query($query); //echo $query;jquery $pollStartHtml = ''; $pollAnswersHtml = ''; while($row = mysql_fetch_array($result)) { $pollQuestion = $row['pollQuestion']; $pollAnswerID = $row['pollAnswerID']; $pollAnswerValue = $row['pollAnswerValue']; if ($pollStartHtml == '') { $pollStartHtml = '<div id="pollWrap"><form name="pollForm" method="post" action="inc/functions.php?action=vote"><h3>' . $pollQuestion .'</h3><ul>'; $pollEndHtml = '</ul><input type="submit" name="pollSubmit" id="pollSubmit" value="Vote" /> <span id="pollMessage"></span><img src="ajaxLoader.gif" alt="Ajax Loader" id="pollAjaxLoader" /></form></div>'; } $pollAnswersHtml = $pollAnswersHtml . '<li><input name="pollAnswerID" id="pollRadioButton' . $pollAnswerID . '" type="radio" value="' . $pollAnswerID . '" /> ' . $pollAnswerValue .'<span id="pollAnswer' . $pollAnswerID . '"></span></li>'; $pollAnswersHtml = $pollAnswersHtml . '<li class="pollChart pollChart' . $pollAnswerID . '"></li>'; } echo $pollStartHtml . $pollAnswersHtml . $pollEndHtml; } function getPollID($pollAnswerID){ $query = "SELECT pollID FROM pollAnswers WHERE pollAnswerID = ".$pollAnswerID." LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_array($result); return $row['pollID']; } function getPollResults($pollID){ $colorArray = array(1 => "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099", "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099"); $colorCounter = 1; $query = "SELECT pollAnswerID, pollAnswerPoints FROM pollAnswers WHERE pollID = ".$pollID.""; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { if ($pollResults == "") { $pollResults = $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter]; } else { $pollResults = $pollResults . "-" . $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter]; } $colorCounter = $colorCounter + 1; } $query = "SELECT SUM(pollAnswerPoints) FROM pollAnswers WHERE pollID = ".$pollID.""; $result = mysql_query($query); $row = mysql_fetch_array( $result ); $pollResults = $pollResults . "-" . $row['SUM(pollAnswerPoints)']; echo $pollResults; } //VOTE START if ($action == "vote"){ if (isset($_COOKIE["poll" . getPollID($pollAnswerID)])) { echo "voted"; } else { $query = "UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID.""; mysql_query($query) or die('Error, insert query failed'); setcookie("poll" . getPollID($pollAnswerID), 1, time()+259200, "/", ".webresourcesdepot.com"); getPollResults(1); } } //VOTE END if (mysql_real_escape_string($_GET['cleanCookie']) == 1){ setcookie("poll1", "", time()-3600, "/", ".webresourcesdepot.com"); header('Location: http://webresourcesdepot.com/wp-content/uploads/file/ajax-poll-script/'); } ?> database_connection.php <?php require_once 'app_config.php'; mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or handle_error("there was a problem connecting to the database that holds the information we need to get you connected.", mysql_error()); mysql_select_db(DATABASE_NAME) or handle_error("there's a configuration problem with our database.", mysql_error()); Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 3, 2012 Share Posted February 3, 2012 This is because your query is failing and returning false, debugging measures should be in place. $result = mysql_query($query); if(!$result) { echo $query . "<br />"; echo mysql_error(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.