Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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

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

 
Share this answer
 
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900