bob971
Invité n'ayant pas de compte PHPfrance
02 sept. 2011, 12:41
re,
je mets le code en entier, car malgré tout l'erreur est toujours là.
Notice: Undefined index: sujet in C:\wamp\www\hymnes_louange\3.php on line 13
Notice: Undefined index: corps in C:\wamp\www\hymnes_louange\3.php on line 13
Erreur : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '542' AND sujet = NULL AND corps <= NULL' at line 1
pour la page "page.php".
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=moki', 'root', '', $pdo_options);
if(isset($_GET['lettre']))
{
$reponse = $bdd->query('SELECT id, sujet FROM news WHERE sujet LIKE \''.$_GET['lettre'].'%\' ORDER BY sujet');
}
else
{
$reponse = $bdd->query('SELECT id, sujet FROM news ORDER BY sujet');
}
while ($donnees = $reponse->fetch())
{ ?>
<a href="3.php?id=<?php echo $donnees['id']; ?>"> <?php echo $donnees['sujet'] . ' ... ' . $donnees['id'] . ' <br /> '; ?></a>
<?php }
$reponse->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
?>
pour la page "3.php"
<?php
if (isset($_GET['id']))
{
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=moki, 'root', '', $pdo_options);
$req = $bdd->prepare('SELECT id FROM news id = ? AND sujet = ? AND corps <= ? ');
$req->execute(array($_GET['id'],$_GET['sujet'], $_GET['corps']));
while ($donnees = $req->fetch())
{
echo $donnees['sujet'] . ' '. $donnees['id'] . '<br/>' . $donnees['corps'];
}
$req->closeCursor();
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
}
?>