The query does not produce any results. The variable response is supposed to hold the query result but when I test it contain using var_dump it shows that it is empty.
try
{
$bdd = new PDO('mysql:host=localhost;dbname=ems', 'root', '');
} catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$code=123456;
$query = $bdd->prepare('SELECT Code,sender FROM info WHERE Code = ?');
//,reciever,origin,destination,transit
$query->execute(array($code));
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
} else{
echo" The Code entered was not found please verify and enter again";
}
I'm not sure if this was simply a typo in your code, but I noticed this block of code:
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
else{
echo" The Code entered was not found please verify and enter again";
}
}
Looking at your code (and your comment), you have an open brace {
for the if
statement, followed by an open brace for the while
loop. Then there is a closing brace. The closing brace }
is for the while
loop. Then you have an pair of braces for the else
block. You also have another }
after the else
block. Try adding a }
before your else
block and remove one of the }
after the else
block. The else
block should not be nested in the if
block (if I understand you completely). This is a syntax error.
How the code should look:
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
}
else{
echo" The Code entered was not found please verify and enter again";
}