0

I've looked everywhere and have no idea why my query wont work!

<table>
<?php
    $con = mysqli_connect("127.0.0.1","root","pass","database");

    $query = mysqli_query("SELECT role FROM dicetrack");
    while($row = mysqli_fetch_array($query))
    {
        echo "<tr><td>" + $row["role"] + "</td></tr>";
    }

    mysqli_close($con);
?>
</table>

Im trying to record dice roles from different users. Everything seems to work fine but when i test the query in any way possible, it comes out to fail. Does anyone know what i did wrong? I've checked all spelling like 10 times and still cant find anything. Thanks in advance.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Ozay34
  • 107
  • 1
  • 3
  • 9

2 Answers2

2

mysqli_query() takes two parameters: the mysqli connection and your query:

$query = mysqli_query("SELECT role FROM dicetrack");

should be:

$query = mysqli_query($con, "SELECT role FROM dicetrack");

You need to enable error reporting as PHP would throw an error explaining this to you.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
2
$query = mysqli_query("SELECT role FROM dicetrack");

You didn't specify the connection.

$query = mysqli_query($con, "SELECT role FROM dicetrack");

Correct one.

prq
  • 271
  • 2
  • 9