Click here to Skip to main content
14,484,364 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am receiving the error "Call to undefined function mysql_fetch_assoc()" on this line of code;

while ($row =mysql_fetch_assoc($result)){


This is the full php code I am using for the function. It is initially to upload a users profile picture

<?php 
if (!isset($_SESSION["currentUser"])) 
     header("Location: userprofilepage.php");
session_start();
include("dbConnect.php");

$sql = "SELECT * FROM Users";
$result = $conn->query($sql);


if (($result ) >0) {
	while ($row =mysql_fetch_assoc($result)){
    $id =$row['id'];
	$queryImg = "SELECT * FROM profileimg WHERE userid='$id'";
	$stmtImg = mysql_query($conn, $queryImg);
    while ($rowImg =mysql_fetch_assoc($resultImg))	{
		echo "<div>";
		if (rowImg['status'] ==0) {
			echo "<img src ='uploads/profile".$id.".jpg?".mt_rand()."'>";
		} else {
			echo "<img src='uploads/profiledefault.jpg'>";
		}
		echo $row['username'];
		echo "</div>";
	}
	}
} else {
	echo "There are no users yet!";
}

?>


What I have tried:

I have tried replacing this and trying other functions but I cant get my head around it.
Posted
Updated 26-Feb-20 22:17pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

You have:
while ($rowImg = mysql_fetch_assoc($resultImg))

but nowhere do you define $resultImg
You actually put your query results in $stmtImg

   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Most likely the reason is that you're using PHP 7.0 (or later).


Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100