$result = mysql_query("
SELECT q.*, IF(v.id,1,0) AS voted
FROM quotes AS q
LEFT JOIN quotes_votes AS v 
ON 	q.id = v.qid
	AND v.ip =".$ip."
	AND v.date_submit = '".$today."'
");

$i=1;
$str='';
$script='';

while($row=mysql_fetch_assoc($result))
{
	// Looping through all the quotes and generating the list on the right of the page:
	
	$str.= '<div class="thumb" id="q-'.$i.'">'.substr($row['txt'],0,20).
	'<span class="points">...</span><div class="star-rating" id="rating-'.$i.'">';
	
	$row['rating'] = round($row['rating']);
	for($z=0;$z<5;$z++)
	{
		$str.='<input type="radio" name="rate-'.$i.'" value="'.($z+1).'" '.($z+1==$row['rating']?'checked="checked"':'').' disabled="disabled" />';
	}

	$str.='</div></div>';
	
	// Each quote calls the fillData JS function
	$script.="fillData(".formatJSON($row).");".PHP_EOL;
	
	$i++;
}

This is a Code for Quotation Script where User can Vote for the Quotation and Stuff..
But whenever I run this I encounter this Error:-

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/index.php on line 31

Please Help! Thank You! :D

Dani AI

Generated

The warning means the fetch function was given a boolean instead of a result resource — most often because the SELECT failed and mysql_query returned false. As suggested, a malformed or broken query is the usual reason, but a failed connection or unset variables used inside the SQL can produce the same symptom.

Quick diagnostic steps:

  • Verify the DB connection and selected database before running the query.
  • Dump the final SQL string to logs or the page and run it directly in the DB client (phpMyAdmin / mysql CLI) to see the engine's error.
  • After calling the query, check for errors and stop before calling any fetch functions.

Example safe check (do not call fetch unless $result is truthy):

$sql = '/* the final SELECT SQL string built at runtime */';
$result = mysql_query($sql);
if ($result === false) {
    error_log('MySQL error '.mysql_errno().': '.mysql_error().' | SQL: '.$sql);
    // abort further fetching/processing
}

Practical points tied to this thread:

  • Ensure variables used inside the WHERE/ON clause (IP, date, etc.) are set, correctly quoted, and escaped. An unquoted string with embedded quotes or dots will break SQL syntax.
  • Isolate the failing fragment: try the SELECT without the JOIN, then add parts back until it breaks.
  • Avoid printing raw DB errors in production; log them and show a friendly message instead.
  • The mysql_* extension is removed in modern PHP. Consider converting to mysqli or PDO and use prepared statements (bind parameters) to eliminate quoting/escaping mistakes and prevent injection.

A short mysqli example pattern for the same workflow (use parameter binding rather than concatenation) will both remove this class of error and improve long-term maintainability.

Member Avatar for Member #334542

The error will come because of your formation of query. If you misplaced And or Where the error will trigger. So check whether the formation of query is correct or not?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.