0

I wrote this simple php script that just to import basic information from mysql table. As a result, not even a error message, but a blind screen. When I suppress the DB code, php code works just fine and is displayed. Something to do with the PHP - Mysql connection, but cant determine it since:

  • Apache2 is installed and is working (2.2.22)
  • PHP and Mysql are installed with php5-msql bundle (last version 5.3.10).
  • PhpMyAdmin seems to work fine.

Anything else ? Thanks

<p> Voici le resultat de la verification: 
<?php 
if ($_POST ['password'] == "XXXXXX")
{
echo "Vous avez ete identifie avec le mot de passe" . htmlspecialchars($_POST['password']);
}
else
{
echo "Vous avez echoue";
}
?>
</p>

<p> Si tu veux retenter ta chance, <a href="Password.php"> clique ici </a>
</p>

<?php
try
{
//Connexion à Mysql
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', 'XXXXX');
}
catch(Exception $e)
{
// Exception pour erreur
 die ('Erreur : ' .$e->getMessage()); 
}
// Si tout va bien récuperation de la table
$reponse = $bdd->query('SELECT * FROM billets'); 


// On affiche les entrees une à une
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong> Livraison du contenu de chat </strong>
<?php echo $donnees ['titre']; ?>
a laissé le message suivant 
 <?php echo $donnees ['contenu']; ?>
</p>
}
<?php
$reponse->closeCursor(); // termine le traitement
?>
Vico la patate
  • 209
  • 2
  • 4
  • 12
  • Start by setting the [error level](http://www.php.net/manual/en/function.error-reporting.php) to `E_ALL`: `error_reporting(E_ALL)` – CodeZombie May 08 '14 at 18:46
  • I added this code but nothing changes: still got the blind screen when using php with mysql – Vico la patate May 08 '14 at 19:09
  • When in development, add `$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);` right after the connection is opened. Try and show us the HTML form that goes with this. Plus see if removing the space in `$donnees ['titre']` will help --- `$donnees['titre']` etc. – Funk Forty Niner May 08 '14 at 23:03
  • I first tried your solution, but still a blind screen. Then I tried to suppress the code from the query line, and it worked, proving that database can be connected to php. The problem must be related to the execution of the query by mysql – Vico la patate May 09 '14 at 07:30
  • after testing, it seems that the problem come form the line while ($donnees = $reponse->fetch()) – Vico la patate May 09 '14 at 09:13
  • Before writing any further code, make sure your test environment is properly set up. This especially includes error reporting (see http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php). Developing a PHP application without it is pointless, unless you have a debugger. After this you can start locating the problem. At the end there is no "it seems to be on line X", but a "the problem is on line X". – CodeZombie May 15 '14 at 10:15

0 Answers0