2016-04-19 14 views
0

私はいくつか試してきましたが、うまくいかなかった。 ここに私の要求です:それは代わりに番号で動作します:しかし、私は変数を使用しようとすると、それはしません。 私はあなたの助けや、どこを見るかへの手がかりを非常に感謝しています。念のためpdo prepare文は制限付きで動作しません

$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, :limit'); 
$req->bindParam(':limit',$page,PDO::PARAM_INT); 

全体コード: 歓声、問題の原因 K.

ライン

<?php 
//echo $_COOKIE['pseudo'] ."<br>"; 
?> 

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
</head> 
<body> 

<form action="minichat_post.php" method="POST"> 
    <label for="pseudo">Pseudo</label> 
    <input type="text" name="pseudo" value="<?php 
    if (isset($_COOKIE['pseudo'])) { 
     echo $_COOKIE['pseudo']; 
     }else{echo "";};?>"> 
    <br /><br /> 
    <label for="msg">message</label> 
    <input type="text" name="msg"><br /><br /> 
    <input type="submit" value="Envoyer"> 
</form> 

<div class="container"> 

<?php 
//connection 
try 
{ 
    $bdd = new PDO('mysql:host=localhost;dbname=minichat;charset=utf8', 'root', 'root'); 
} 
catch (Exception $e) 
{ 
     die('Erreur : ' . $e->getMessage()); 
} 

//requête 
$req = $bdd->query('SELECT * FROM Twit ORDER BY id DESC LIMIT 0,10'); 
//récupération 
while ($donnees = $req->fetch()){ 
    echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['msg']) . '</p>'; 
} 
$req->closeCursor(); 
?> 
<form action="" method="GET"> 
<label for="page">Combien de msg voulez vous voir</label> 
<input type="text" name="page"> 
<input type="submit" value="voir"></input> 
</form> 

<?php 
$page=htmlspecialchars($_GET['page']); 

//connection 
if (isset($page) && !empty($page)) { 
    try 
{ 
    $bdd = new PDO('mysql:host=localhost;dbname=minichat;charset=utf8', 'root', 'root'); 
} 
catch (Exception $e) 
{ 
     die('Erreur : ' . $e->getMessage()); 
} 


//request WHERE MY PROBLEM IS 
/*I've tried that - din't work neither 
$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, ?'); 
$req->execute(array(htmlspecialchars($_GET['page'])));*/ 

$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, :limit'); 
$req->bindParam(':limit',$page,PDO::PARAM_INT); 


print_r($req); 

//fetchingdata 

    while ($donnees = $req->fetch()){ 
     echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['msg']) . '</p>'; 
    } 
} 

$req->closeCursor(); 
?> 
</div> 

</body> 
</html> 

答えて

0

は(int型)$ページ

として$ページ変数をキャストしてみ
関連する問題