Jump to content

help w/ mysql_fetch_array(): error


Aaron4osu

Recommended Posts

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());

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.