2014-04-23 2 views
0

다음 코드를 사용하여 데이터베이스를 쿼리하지만 페이지가 비어 있습니다!웹 양식의 단일 사용자 입력으로 데이터베이스 쿼리

어디에 문제가 있는지 알 수 없습니다. 도와주세요.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title>Extract Student Data</title> 
</head> 
<body bgcolor="white"> 
<?php 
    include 'db.inc'; 

    // Show all student data in a <table> 
    function displayStudentsList($connection,$query,$Year) 
    { 
     // Run the query on the DBMS 
     if (!($result = @ mysql_query ($query, $connection))) 
     showerror(); 

     // Find out how many rows are available 
     $rowsFound = @ mysql_num_rows($result); 

     // If the query has results ... 
     if ($rowsFound > 0) 
     { 
     // ... print out a header 
     echo "Students data Of Year $Year<br>"; 

     // and start a <table>. 
     echo "\n<table>\n<tr>" . 
     "\n\t<th>Admission No.</th>" . 
     "\n\t<th>Last Name</th>" . 
     "\n\t<th>First Name</th>" . 
     "\n\t<th>Gender</th>" . 
     "\n\t<th>Orphan</th>" . 
     "\n\t<th>District</th>\n</tr>"; 

     // Fetch each of the query rows 
     while ($row = @ mysql_fetch_array($result)) 
     { 
     // Print one row of results 
     echo "\n<tr>" . 
     "\n\t<td>" . $row["Admission"] . "</td>" . 
     "\n\t<td>" . $row["last_name"] . "</td>" . 
     "\n\t<td>" . $row["first_name"] . "</td>" . 
     "\n\t<td>" . $row["Gender"] . "</td>" . 
     "\n\t<td>" . $row["Orphan"] . "</td>" . 
     "\n\t<td>" . $row["District"] . "</td>" . 
     "\n</tr>"; 
     } // end while loop body 

     // Finish the <table> 
     echo "\n</table>"; 
     } // end if $rowsFound body 

     // Report how many rows were found 
     echo "$rowsFound records found matching your 
     criteria<br>"; 
    } // end of function 

    $scriptName = "combined.php"; 

    // Has the user provided the parameter? 
    if (empty($Year)) 
    { 
     // No, the user hasn't provided a parameter 
    ?> 
     <form action="<?=$scriptName;?>" method="GET"> 
     <br>Enter Year Of Admission : 
     <input type="text" name="Year" value="All"> 
     (type All For All Years) 
     <br> 
     <input type="submit" value="Show Data"> 
     </form><br> 
     <a href="index.html">Home</a> 
    <?php 
    } // end of if empty($Year) body 
    else 
    { 
     // Secure the user parameter $Year 
     $Year = clean($Year, 30); 

     // Connect to the MySQL DBMS 
     if (!($connection = @ mysql_connect($hostName, 
      $username, 
      $password))) 
     die("Could not connect"); 

     if (!mysql_select_db($databaseName, $connection)) 
     showerror(); 

     // Start a query ... 
     $query = "SELECT Admission, 
     last_name, 
     first_name, 
     Gender, 
     Orphan, 
     District 
     FROM  osasaasasaalumni_index;" 

     // ... then, if the user has specified a year, 
     // add the Year as an AND clause ... 
     if ($Year != "All") 
     $query .= " AND year = \"$Year\""; 

     // ... and then complete the query. 
     $query .= " ORDER BY last_name"; 

     // run the query and show the results 
     displayStudentsList($connection, $query, $Year); 

     // Close the DBMS connection 
     mysql_close($connection); 
    } // end of else if empty($Year) body 
?> 
</body> 
</html> 

내 db.inc 내가 그것을 호출 할 때, 그것은 빈 페이지를 표시하기 때문에 코드가 무슨 잘못

<? 
    $hostName = "xxxxxx"; 
    $databaseName = "xxxxx"; 
    $username = "xxxxx"; 
    $password = "xxxxx"; 
?> 

입니까? 원래

: 업데이트

$query = "SELECT Admission, 
    last_name, 
    first_name, 
    Gender, 
    Orphan, 
    District 
    FROM  osasaasasaalumni_index;" 

:

+0

여러 가지 이유가있을 수 있습니다. 'ini_set ('error_reporting', E_ALL);에 의한 오류보고를 가능하게하십시오. –

+0

코드에 다음과 같은 문법 오류가 있습니다 :'@ mysql_connect' 그것은'@ mysql_connect'이어야합니다 –

+0

오류를 전혀 억제해서는 안됩니다. – Quentin

답변

0

이 문장의 끝에 ; 누락

$query = "SELECT Admission, 
    last_name, 
    first_name, 
    Gender, 
    Orphan, 
    District 
    FROM  osasaasasaalumni_index;"; 

당신이 빈 페이지없이 오류를 볼 경우에, 당신이해야 오류보고를 켜십시오. 예를 들어이 코드를 스크립트 시작 부분에 넣으면 (예 : <?php)

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
관련 문제