1

I'm trying to create a database with MySQL and PHP, however using echo does not work after calling require_once.


<?php
echo "before";
require_once("../mysql_connect.php");
echo "after";
$query = "SELECT first_name, last_name, email, password FROM account";
$response = @mysqli_query($dbc, $query);
if($response){

    echo '<table align="left"
cellspacing="5" cellpadding="8">

<tr><td align="left"><b>First Name</b></td>
<td align="left"><b>Last Name</b></td>
<td align="left"><b>Email</b></td>
<td align="left"><b>Password</b></td>';
    while($row = mysqli_fetch_array($response)){

    echo '<tr><td align="left">' . 
         $row['first_name'] . '</td><td align="left">' . 
         $row['last_name'] . '</td><td align="left">' .
         $row['email'] . '</td><td align="left">' . 
         $row['password'] . '</td><td align="left">';
    echo '</tr>';
    }

    echo '</table>';

} else {

    echo "Couldn't issue database query<br />";

    echo mysqli_error($dbc);

}
mysqli_close($dbc);

?>

If run through the terminal, this works exactly as expected. When run through a web browser, it only prints out 'before' and nothing else. Does anyone know how to fix this? Thanks in advance.

alpaca423
  • 11
  • 2
  • 2
    `error_reporting(E_ALL); ini_set('display_errors', '1');` – AbraCadaver May 10 '19 at 21:04
  • 1
    Don't use `@` when you're debugging, the error messages that it suppresses can be useful. – Barmar May 10 '19 at 21:28
  • Thanks, I found the problem and fixed it, the permissions were wrong. – alpaca423 May 10 '19 at 21:43
  • [How to enable MySQLi exception mode?](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments/22662582#22662582) – Dharman May 10 '19 at 22:38
  • **Never store passwords in clear text or using MD5/SHA1!** Only store password hashes. Use PHP's [`password_hash()`](http://php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://php.net/manual/en/function.password-verify.php) . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the [password_compat](https://github.com/ircmaxell/password_compat) library to get the same functionality. – Dharman May 10 '19 at 22:39

0 Answers0