Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


whay i cant retrive the data ?

heres code i think error is in line "$results = $db->query("SELECT * FROM teacher WHERE name=$name AND password=$password ");"

$db = new PDO("mysql:host=localhost;dbname=feedback;port=8808","root","krishna");
$db->exec("SET NAMES 'utf8'");
catch (exception $e){
    echo'Could Not Connect To The Database';
    $results = $db->query("SELECT * FROM teacher WHERE name=$name AND password=$password ");
} catch (Exception $ex) {
    echo 'Data Can Not Be retrived';

Sorry, if you refresh the page it should be there now.

Try changing fetchall to fetchAll - could help.

nop not workng

2 Answers

Try a prepared statement:

$stmt = $db->prepare("SELECT * FROM teacher WHERE name = :name AND password = :password ");
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
 } catch (Exception $ex) { 
echo 'Data Can Not Be retrived'; exit(); } 



If you're not getting anything in your var_dump, I might suggest checking your SQL query in your phpMyAdmin or another query program to make sure that the query itself is working.

You're getting the catch from your second try/catch block, then, of 'Data can not be retrieved?'

I am getting the result if i replace the veriable name ($name , $password) with string ('krishna' , 'krishna'). its jst not working because of variable.