2017-01-04 4 views
0

데이터베이스를 탐색하고 표를 반환하는 검색 막대를 만들려고합니다. 폼의 값은 저장되지만 PHP 코드는 정보 배열을 반환하지 않습니다. 나는이 작업이는 부트 스트랩 모달 내부에 팝업 메시지가 될 것입니다 얻을 후Html 검색 막대 값이 PHP 코드로 처리되지 않습니다.

<?php 
    header("Location:http://127.0.0.1:58199/graduateYearPage.html"); 
    if (isset($_GET['uni_name']) && is_string($_GET['uni_name'])) { 
     $uname = $_GET['uni_name']; 
    } else { 
     $uname = ""; 
    } 

    $con = new mysqli('127.0.0.1', 'root', 'tR60135400', 'db'); 

    if ($con->connect_errno) { 
     echo "We are experiencing problems."; 
     exit; 
    } 

    $sql = "SELECT * FROM students WHERE university = $uname"; 

    if (!$result = $con->query($sql)) { 
     echo "Sorry, the website is experiencing problems."; 
     exit; 
    } 

    if ($result->num_rows === 0) { 
     echo "We could not find a match for ID $uname, sorry about that. Please try again."; 
     exit; 
    } else { 
     //OUTPUT A TABLE 
     echo "<table> <ul>" 
     while($row = $result->fetch_assoc()){ 
      printf ("<li>%s</li>", $row["firstName"]); 
      printf ("<li>%s</li>", $row["lastName"]); 
      printf ("<li>%s</li>", $row["university"]); 
     } 
     echo "</ul> </table>" 
    } 
    $result->free(); 
    $con->close(); 
    exit; 
?> 

: 여기

는 코드입니다. 테이블이 작동하지 않습니다. 나는 또한 이것이 PHP 코드라고 부르는 형태와 양식 때문일 수도 있다고 생각했다. 여기

양식에 대한 HTML 코드입니다

<form method="GET" id="search_bar" style="text-align: center;"> 
    <div class="input-group"> 
     <input id="placeholder" type="search" class="form-control" name="uni_name" placeholder=" Enter a university name."> 
     <div class="input-group-btn"> 
      <button class="btn btn-default" type="submit" name="submit"> 
      <i class="glyphicon glyphicon-search"></i> 
      </button> 
     </div> 
    </div> 
</form> 
+0

결과가 어떻게됩니까? –

+0

아무런 결과도 얻지 못했습니다. 값을 입력하면 값과 이름이 표시된 코드의 위치가 검색됩니다. http://127.0.0.1:58199/graduateYearPage.html?uni_name = arizona & submit = –

+1

작업을 비워서는 안됩니다 ... html 페이지가 아닌 PHP 페이지 여야합니다 –

답변

0

이 시도 :

index.html을 또는 index.php를

<form method="GET" id="search_bar" action="search_bar.php" style="text-align: center;"> 
    <div class="input-group"> 
     <input id="placeholder" type="search" class="form-control" name="uni_name" placeholder=" Enter a university name."> 
     <div class="input-group-btn"> 
      <button class="btn btn-default" type="submit" name="submit"> 
      <i class="glyphicon glyphicon-search"></i> 
      </button> 
     </div> 
    </div> 
</form> 

search_bar.php을

부트 스트랩에서
<?php 
if($_SERVER["REQUEST_METHOD"]="GET"){ 
    if(isset($_GET["uni_name"])){ 
     $uname = $_GET['uni_name']; 
    }else{ 
     $uname = ""; 
    } 
} 

$con = new mysqli('127.0.0.1', 'root', 'tR60135400', 'db'); 

if ($con->connect_errno) { 
    echo "We are experiencing problems."; 
    exit; 
} 

$sql = "SELECT * FROM students WHERE university = '$uname'"; 

if (!$result = $con->query($sql)) { 
    echo "Sorry, the website is experiencing problems."; 
    exit; 
} 

if ($result->num_rows === 0) { 
    echo "We could not find a match for ID $uname, sorry about that. Please try again."; 
    exit; 
} else { 
    //OUTPUT A TABLE 
    echo "<table> <ul>" 
    while($row = $result->fetch_assoc()){ 
     printf ("<li>%s</li>", $row["firstName"]); 
     printf ("<li>%s</li>", $row["lastName"]); 
     printf ("<li>%s</li>", $row["university"]); 
    } 
    echo "</ul> </table>" 
} 
$result->free(); 
$con->close(); 
exit; 
?> 
+0

그것은 여전히 ​​같은 일을했습니다. 일단 action = "server.php"라고 쓰면 코드를 실행하는 대신 다운로드가 시작됩니다. –

+0

당신의 PHP 버전은 무엇입니까? – Ruben

0

는 "= 데이터 대상"당신이 모달 오프너이 태그의 HREF 태그에 변경해야합니다 모달이나 모달 뷰 모드를 의미하는지 모달 뷰를 열거 나 페이지로 리디렉션 때문에 제거합니다. 또한 검색 쿼리에 문자열이 작은 따옴표로 표시되어야합니다.

SELECT * FROM students WHERE university = '$uname'