提示コードのコメント部内部ですがindex.phpで送信したsubmitをsearch.phpでそれがあるかどうか?を判定しているのですがなぜか常にfalse になってしまいますどう対処したらいいのでしょうか?
参考サイト:http://www.htmq.com/html5/button.shtml
index.php
php
1<!DOCTYPE html> 2<html lang=ja> 3 <head> 4 <meta charset="utf-8"> 5 6 <link rel="stylesheet" href="style.css"> 7 <title>send</title> 8 </head> 9 10 <body> 11 12<?php 13session_start(); 14session_regenerate_id(true); 15ini_set("display_errors",1); 16error_reporting(E_ALL); 17?> 18 19 20<!-- ログアウトアイコン --> 21<?php if(isset($_SESSION['login']) == true) 22{ 23?> 24<!-- ログイン中 --> 25 26 <form action="logout.php" method="post"> 27 <button type="submit"> ログアウト </button> 28 </form> 29 30 <form action="newThread.php" method="post"> 31 <button type="submit"> スレッドを立てる </button> 32 </form> 33 34 35<?php 36} 37?> 38 39 40 41 42 43 44 45<h1 class="center" > 掲示板 </h1> 46//////////////////////////////////////////////////////////////////////////////////////////////// 47<!-- 検索 --> 48<form class="center" action="search.php" method="post"> 49 <input type="text" name="name"><br> 50 <button type="submit"> 検 索 </button> 51 <br> 52</form> 53<br> 54 ////////////////////////////////////////////////////////////////////////////////////////////// 55<?php 56try 57{ 58 $dsn = 'mysql:dbname=Bulletin_Board;host=localhost;charset=utf8'; 59 $dbh = new PDO($dsn,"root",""); 60 $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 61 $sql = 'SELECT * FROM Thread'; 62 $stmt = $dbh->prepare($sql); 63 $stmt->execute(); 64} 65catch(PDOException $e) 66{ 67 die($e->getMessage()); 68} 69 70$count = 0; 71?> 72 73 74 75 76 77<?php foreach($stmt as $item) 78{ 79 $count += 1; 80?> 81<a href="thread.php?title=<?php echo $item['id']?>"> <?php echo $item['name']; ?> </a>   82 83 84 85 <?php 86 if(($count % 8) == 0) 87 { 88 ?> 89 <br> 90 91 92 93<?php 94 } 95} 96?> 97 98 99<?php if(isset($_SESSION['login']) == false) 100{ 101?> 102 <form class="center" action="register.php" method="post"> 103 <button type="submit"> 登録 </button> 104 </form> 105 106 <form class="center" action="login.php" method="post"> 107 <button type="submit"> ログイン </button> 108 </form> 109<?php 110}else 111{ 112?> 113 114 115 116<?php 117} 118?> 119 120 121 122</body> 123 124</html> 125
Search.php
php
1<html lang=ja> 2 <head> 3 <meta charset="utf-8"> 4 <link rel="stylesheet" href="style.css"> 5 <title>send</title> 6 </head> 7 <body> 8 9 10<?php 11session_start(); 12ini_set("display_errors",1); 13error_reporting(E_ALL); 14?> 15//////////////////////////////////////////////////////////////// 16<?php 17if(isset($_POST['submit']) == true) 18{ 19//////////////////////////////////////////////////////////////// 20 print("aaa"); 21 try 22 { 23 $dsn = 'mysql:dbname=Bulletin_Board;host=localhost;charset=utf8'; 24 $dbh = new PDO($dsn,"root",""); 25 $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 26 $dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, 0); 27 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 28 29 $dbh->beginTransaction(); 30 31 $sql = "SELECT id,name FROM Thread WHERE name LIKE '%" . $_POST["name"] . "%' "; 32 $stmt = $dbh->prepare($sql); 33 $stmt->execute(); 34 35 // 検索結果を列挙 36 $result = $stmt->fetch(); 37 if($stmt->rowCount() > 0) 38 { 39 for($i = 0; $i < $stmt->rowCount();) 40 { 41 ?> 42 43 <a href="thread.php?title=".$result[$i]> <?php echo $result[$i + 1] ?> </a><br> 44 45 46 <?php 47 print("thread.php?title=".$result[$i]); 48 $i++; 49 } 50 } 51 else 52 { 53 ?> 54 55 <h1> 該当するスレッドが見つかりません。 </h1> 56 57 <?php 58 } 59 } 60 catch(PDOException $e) 61 { 62 die($e->getMessage()); 63 } 64} 65else 66{ 67 print("bbb"); 68} 69 70?> 71 </body> 72</html> 73
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。