1

i'm trying to fetch data from mysql database using this code :

$con = mysqli_connect('localhost', 'root', '', 'nicu');
    mysqli_query($con, "set NAMES utf8");
    $query = mysqli_query($con, "select * from user");
    while($rows = mysqli_fetch_assoc($query)) :
        $rows = $rows["nicuAddress"];
        $address = $rows["nicuEmail"];
        echo "$rows<br>$address";
    endwhile;

but every time i run this code i get this warning :Warning: Illegal string offset

what changes do i have to do to fix this ?

2
  • Not sure if the cause of your error, but you are overwriting $rows on the first line of the loop. That looks wrong. Commented Jun 12, 2017 at 1:09
  • 1
    @AlexanderO'Mara yep , i didn't notice that thanks alot Commented Jun 12, 2017 at 1:14

1 Answer 1

2

You are trying to reaches a part of the array that was overwritten. After running $rows = $rows["nicuAddress"] you cannot access $address = $rows["nicuEmail"] as an array.

Solution

$address = $rows["nicuAddress"]; // <-- Change to address
$email = $rows["nicuEmail"]; // <-- Change to email
echo "$address<br>$email";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.