2014-01-21 63 views
-1
<?php 
If(isset($_POST['submit'])) 
{ 
    $name=$_POST['user']; 
    require('connect.php'); 
    global $pdo; 
    $stmt= $pdo->prepare("select name from user where name=?"); 
    $stmt->bindparam(1,$name); 
    $stmt->execute(); 
    $row=$stmt->fetch(PDO::FETCH_ASSOC); 
    if($row==false) 
    { 
    die("erorr".print_r($stmt)); 
    } 
    elseif($row['name']==$name) 
    { 
    header("location: mypage.php"); 
    } 
    else 
    { 
    die("please enter your user name and password"); 
    } 
} 
?> 

無差錯代碼PDOStatement對象對象([的queryString] =>選擇名字從用戶其中name =?)erorr1檢查我的代碼幫我PDO語句錯誤校驗碼

+0

值添加完整的錯誤代碼 –

回答

1

也許沒有錯誤。

這個替換

die("erorr".print_r($stmt)) 

$err=$stmt->errorInfo(); 
die('error :'.$err[2]); 

到目前爲止,可能出現的問題在查詢表(或領域)不存在,或者$name在表中沒有匹配。也許你得檢查$stmt->rowCount

see documentation on PDOStatement::errorInfo

+0

在$錯誤[2]你能在這裏解釋一下爲什麼我們使用2 – user3164111

+0

看到鏈接到PHP官方文檔。第二個是最「用戶可讀的」,但也加上'if(0 == $ stmt-> rowCount)'來處理「找不到行」 – Asenar

+0

'<?php 嘗試 { $ pdo = new pdo ('mysql:dbname = test; host = localhost','root','ajeet'); } catch(PDOException $ e) die(「error」。$ e-> getmassage()); } ?>' – user3164111