2012-01-07 4 views
0

が動作していない理由をあまりにもわからない...この準備書は、これはちょうど私のデータベースに挿入されていないいくつかの理由

HTML

<form name="testimonials_form" method="post" action="insert/"> 
    Name 
    <input type="text" name="from" maxlegnth="100" /> 
    Location 
    <input type="text" name="where" maxlegnth="100" /> 
    Text Snippet 
    <input type="text" name="text" maxlegnth="255"> 
    <input type="submit" name="submit" value="Continue" /> 
</form> 

PHP

<?php 

$from = $_POST['from']; 
$where = $_POST['where']; 
$text = $_POST['text']; 

if (!$from || !$where || !$text) { 
    $error = "You have missed some fields."; 
    $solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>."; 
} else { 
    $data_array = array(':from' => $from, ':where' => $where, ':text' => $text); 

    $insert_testimonial = $connect->prepare(" 
    INSERT INTO `testimonials` (
     text, from, where 
) VALUES (
     :text, :from, :where 
) 
    "); 

    $insert_testimonial->execute($data_array); 

    $amount = $insert_testimonial->rowCount(); 

    if ($amount < 1) { 
    $error = "Something went wrong."; 
    $solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>."; 
    } else { 
    header ("Location: ../"); 
    } 
} 

?> 

私が戻ってきたのは私のカスタムエラーです "何かが間違っていた" 500エラー(内部サーバーエラー)はありません。$ from、$ whereと$ textを入力するとフォームに入力したものが表示されますが、間違って書いた場合には約5回書き直しました。まだ運がない。私はシンボルが見つからない、または間違った場所に500エラーを返すことができないことを知っています。

誰にも何があるかについての手掛かりはありますか?私はこの無数の時代のようなコードを書いてきましたが、これは動作していないようですので、何かが欠けているはずです。クエリで

+0

あなたは 'errorCode'をチェックしましたか?[DOC](http://www.php.net/manual/en/pdostatement.errorcode.php) –

+1

[' bindParam() '](http: //www.php.net/manual/ja/pdostatement.bindparam.php)? @Shipluが述べているように、エラーコードや[エラー情報](http://www.php.net/manual/en/pdo.errorinfo.php)もチェックしてください。 –

+0

ちょうど 'bindParam'も試して、名前のついたプレースホルダーとマークされたプレースホルダーの両方で試してみました。エラー情報については、私はこれを取り戻しています: 'Array([0] => 42000 [1] => 1064 [2] =>あなたのSQL構文に誤りがあります。バージョンは、 'from、where、text)VALUES ...'の近くで使用するためのバージョンです。このコードは次のとおりです: 'print_r($ insert_testimonial-> errorInfo());' – Joe

答えて

1
from, where 

fromwhereなど

`from`, `where` 

する必要がMySQLでの予約語されています

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

ものは仕方によって、バッククォートです。 IMOでは、これらの単語を列名として使用しないほうがよいでしょうが、そうした場合、最も頻繁にバッククォートを使用する必要があります。

関連する問題