-2

I just want to make a table that let me view the list of rows on my database... But my code won't work, here is my whole code:

$con=mysqli_connect("fd***.biz.nf","1549087_admin","*****","******");
$sql = "SELECT * FROM Solo;";
$myData = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>Grade/Yr. Level</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Position</th>
<th>Motto</th>
</tr>";

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC))
{
echo "<tr><td>";
echo $row['gradeyrlevel'];
echo "</tr><td>";
echo $row['firstname'];
echo "</tr><td>";
echo $row['middlename'];
echo "</tr><td>";
echo $row['lastname'];
echo "</tr><td>";
echo $row['age'];
echo "</tr><td>";
echo $row['position'];
echo "</tr><td>";
echo $row['motto'];
echo "</tr><td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);

Please help me.

the error is:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /srv/disk10/1549087/www/rooseveltcollegecainta.co.nf/admin/adminpage/index.php on line 125

line 125 is

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC))
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132
  • What does it mean "not work"? Which error do you retrieve? – Alessandro Minoccheri Dec 21 '13 at 09:58
  • more details would be helpfull. what exactly does not work? – Markus Kottländer Dec 21 '13 at 10:00
  • This is the error appeared: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /srv/disk10/1549087/www/rooseveltcollegecainta.co.nf/admin/adminpage/index.php on line 125 – user3026685 Dec 21 '13 at 10:01
  • this error means that you have a mysql error, try echoing it – Alireza Fallah Dec 21 '13 at 10:06
  • As per [**your other question**](http://stackoverflow.com/questions/20716989/why-is-my-values-wont-insert-to-my-database) you have in your code `INSERT INTO SOLO` with `SOLO` in upper-case letters, and in this question, you're showing `SELECT * FROM Solo` with `Solo` being in mixed case letters. **Which one is it?** `SOLO` or `Solo`, or `solo`, or `SoLo`.............???? If you had proper error reporting, you would have seen an error saying `table Solo... not found` **AND** get rid of the extra semi-colon in `$sql = "SELECT * FROM Solo;";` as given in an answer below. – Funk Forty Niner Dec 21 '13 at 15:13

6 Answers6

0

While Using mysqli you need to pass the connection variable try using

**$result=mysqli_query($con,$query);**

instead of $result=mysqli_query($query); hope this works

0

Try this:

$mysqli = new mysqli(HOST,USER,PASS,DATABASE);
if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
}
$query  = "SELECT * FROM Solo";
$result = $mysqli->query($query);
while($row    = $result->fetch_array(MYSQLI_ASSOC))
{
     echo "<tr>";
  echo "<td>" . $row['gradeyrlevel'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['middlename'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
   echo "<td>" . $row['position'] . "</td>";
 echo "<td>" . $row['motto'] . "</td>";
 echo "</tr>";
}
DS9
  • 2,843
  • 4
  • 48
  • 99
0
    try this............ 
    $con=mysql_connect("host","username","password");
    mysql_select_db('dbname');
    $query="SELECT * FROM SOLO";
    $result=mysql_query($query);

    while($data = mysql_fetch_row($result))
    {
        .
        .
        .
        .
        .

   }
0

The error means the variable $result is set to false instead of the result of a query. Check if the table name you supplied is correct and does the database user you used to log in has access to it.

Amged Rustom
  • 1,639
  • 3
  • 21
  • 25
0

You have put a semicolon inside mysqli query so you found this error.you have to use following code

$result = mysqli_query($con,"SELECT * FROM Solo");
Anil Meena
  • 813
  • 1
  • 11
  • 27
0

As per your other question here, you obviously have your table name wrong (word/letter-case).

In that question, and I quote from what you said: "IT WORKED!! THANK YOU SO MUCH!! :)"

(LINK to comment)

Two possible errors.

1) Mispelled table name. SOLO instead of Solo (which is most likely the case).

2) Extra semi-colon => $sql = "SELECT * FROM Solo;";
Replace with => $sql = "SELECT * FROM Solo";

And if that doesn't work, then double-check the letter case of everything, such as:

  • Table name
  • Column names
  • Including your DB connection
  • Make sure that the columns exist and are named correctly
  • Check Everything

N.B.: Solo is not the same as SOLO or solo


Try this now, but do read the footnotes below, as they contain some important information that will prove to be beneficial in your learning SQL and PHP.

$con=mysqli_connect("fd***.biz.nf","1549087_admin","*****","******");

// Check connection
if (mysqli_connect_errno($con))
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT * FROM `SOLO`"; // added backticks around SOLO table name

if($sql === FALSE) {
die(mysqli_error()); // TODO: better error handling
}

$myData = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>Grade/Yr. Level</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Position</th>
<th>Motto</th>
</tr>";

while($row = mysqli_fetch_array($myData, MYSQLI_ASSOC))
{
echo "<tr><td>";
echo $row['gradeyrlevel'];
echo "</tr><td>";
echo $row['firstname'];
echo "</tr><td>";
echo $row['middlename'];
echo "</tr><td>";
echo $row['lastname'];
echo "</tr><td>";
echo $row['age'];
echo "</tr><td>";
echo $row['position'];
echo "</tr><td>";
echo $row['motto'];
echo "</tr><td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);

Footnotes:

Suggested tutorials: (although there are many others that can be found on the Web)

and of course, the PHP and MySQL manuals:

Community
  • 1
  • 1
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132