Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error caused page to close and reopen - PHP/HTML

I'm writing a query that checks a column to see if it has a value of 0 and then list all of the findings in a table. The data consist of 5 columns and 140 rows of possible data.

Whenever I load this page it takes 8 - 10 seconds to load and then gives me an error saying that an error with the webpage cause IE to close and reopen the page. Any idea what could be causing this error or the long load time?

<?php 
include 'login.php';

   $con=mysqli_connect($host,$user,$password,$db);
// Check connection
if (mysqli_connect_errno())
 {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Persons");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?> 
like image 224
meverhart913 Avatar asked Nov 29 '25 21:11

meverhart913


1 Answers

It looks like you might not be establishing your connection correctly.

This line -

$con-mysqli_connect($host,$user,$password,$db);

appears that you are trying to connect to the database, but is incorrectly written as a variable.

Also judging by your mysqli_close($con) statement, it's clear to me that you meant to assign $con to the connection.

Try,

$con = mysqli_connect($host, $user, $password, $db);
like image 78
ddavison Avatar answered Dec 02 '25 09:12

ddavison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!