radioボタンによって選択された値を元にデータベースを検索、検索結果を表示するというコードを書いたつもりですが、Catchable fatal error: Object of class mysqli_result could not be converted to string in ~ といったエラーがでてしまい、結果を表示することができません。
index.php <?php $connect = mysqli_connect('HOSTNAME','USER','PASS','DBNAME') or die('error'); echo 'success'; ?> <?php $post = $_POST["fruits"]; $query = mysqli_query( $connect,"select * from radiobutton_search where fruits = '$post'"); while($result = mysqli_fetch_assoc($query)){ echo $result['fruits']; } ?> index.html <form action="index.php" method="POST"> <input type="radio" name="fruits" value="バナナ">バナナ <input type="radio" name="fruits" value="りんご">りんご <input type="radio" name="fruits" value="オレンジ">オレンジ <input type="submit" value="検索"> </form> //値の検証 var_dump($query); object(mysqli_result)[2] public 'current_field' => int 0 public 'field_count' => int 2 public 'lengths' => null public 'num_rows' => int 1 public 'type' => int 0 var_dump($post); string 'りんご' (length=9)
checkboxで検索システムについても質問させていただいたのですが、どうやら似たようなエラーが出てしまいます。
optionタグによる検索、検索結果の表示はできたのですが、radioボタンの方はなぜかうまくいきません。。。
エラーを解決し、検索結果表示するにはどうしたらよいでしょうか?
※SQLインジェクションやバリデーションチェックは省略しております。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/23 09:58
2015/09/23 10:01
退会済みユーザー
2015/09/23 10:39
2015/09/23 10:55