2012-08-24 169 views
0

我想從一個數據庫中獲取一個php頁面,我是PHP新手,我已經使用了Google和閱讀,但我只是沒有得到它。我有一個鏈接到PHP的HTM頁面,因爲我試圖根據選中的複選框和在標準框中提交的信息返回一些數據。這是我到目前爲止,我一直在搞一些試圖讓它工作的查詢,所以如果我可以讓一個人工作,我可以讓餘下的人做我想做的事。我知道我的代碼可能不符合什麼標準,但這不是我的專業,我只是一個試圖讓他的項目工作的學生。請引導我走向正確的方向。Php to MySql select select not working

編輯:這是一個學校項目,我有&我必須使用他們的服務器,在這種情況下恰好是mysql。我沒有得到任何回報,沒有任何錯誤或任何事情。當我從我的htm頁面轉到我的php頁面時,沒有任何反應。我只是簡單地說,我可能不得不開始只運行一個簡單的查詢來調試,以確保我可以獲取任何內容,然後從那裏進行修改。我從來沒有使用複選框,也沒有以前運行過查詢,所以我不得不相信這是我的錯誤所在。我所有的插入和更新語句都在我的其他頁面上工作,但代碼用於選擇語句並將其放入變量的方式對我來說非常混亂。

我的htm網頁:

<html> 
<head> 
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> 
<link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<span class="spanFormat"><form><input type="button" value="Create a New Ticket" onClick="window.location.href='listinput.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="Resolve a Ticket" onClick="window.location.href='resolution.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="Search for a Ticket" onClick="window.location.href='searchinput.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="View Documentation" onClick="window.location.href='documentation.htm'"></form></span> 
<?php 

    DEFINE('DB_USER',); 
    DEFINE('DB_PASSWORD',); 
    DEFINE('DB_NAME',); 
    DEFINE('DB_HOST','localhost'); 

    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 

    if(!$con){ 
    die('Could not connect: '.mysql_error()); 
    } 
    $db_selected = mysql_select_db(DB_NAME, $con); 
    if(!$db_selected){ 
    die('can\'t use'. DB_NAME . ':'.mysql_error()); 
    } 
    ?> 
    <form action="searchinput.php" method="post"> 
<p> 
     How would you like to search?<br/> 

     <input type="checkbox" name="formDoor[]" id="Ticket_ID" value="Ticket_ID" />By Ticket Number<br /> 
     <input type="checkbox" name="formDoor[]" id="Last_Name" value="Last_Name" />By Last Name<br /> 
     <input type="checkbox" name="formDoor[]" id="Station_ID" value="Station_ID" />By Station ID<br /> 
     <input type="checkbox" name="formDoor[]" id="Date" value="Date" />By Date<br /> 
     <input type="checkbox" name="formDoor[]" id="Description" value="Description" />By Description 
    </p> 

    <td>Criteria</td> 
    <td><input type=text name="Criteria" size=30> </td> 
    </form> 
    <input type=submit name="submit" value="Search"> 
    </body> 
</html> 

這裏是我的PHP:

<html> 
<head> 
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> 
<link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<span class="spanFormat"><form><input type="button" value="Create a New Ticket" onClick="window.location.href='listinput.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="Resolve a Ticket" onClick="window.location.href='resolution.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="Search for a Ticket" onClick="window.location.href='searchinput.htm'"></form></span> 
<span class="spanFormat"><form><input type="button" value="View Documentation" onClick="window.location.href='documentation.htm'"></form></span> 
<?php 

    DEFINE('DB_USER',); 
    DEFINE('DB_PASSWORD',); 
    DEFINE('DB_NAME',); 
    DEFINE('DB_HOST','localhost'); 

    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 

    if(!$con){ 
    die('Could not connect: '.mysql_error()); 
    } 
    $db_selected = mysql_select_db(DB_NAME, $con); 
    if(!$db_selected){ 
    die('can\'t use'. DB_NAME . ':'.mysql_error()); 
    } 

    extract($_POST); 

    $Ticket_ID = ($_POST['Criteria']); 
    $Last_Name = ($_POST['Criteria']); 
    $Station_ID = ($_POST['Criteria']); 
    $Date = ($_POST['Criteria']); 
    $Description = ($_POST['Criteria']); 

if(isset($_POST['$Ticket_ID'])) 
{$sql = "select Ticket_ID, customer.Customer_ID, First_Name, Last_Name, Phone_Num, Email, stations.Station_ID, Room_ID, Floor_ID, building.Building_ID, Location, incident_sheet.Description, Summary, assign_groups.Group_ID, assign_groups.Description, resolutions.Resolution_ID, resolutions.Description from customer,stations,resolutions,assign_groups, building, incident_sheet WHERE customer.Customer_ID=incident_sheet.Customer_ID AND stations.Station_ID = customer.Station_ID AND building.Building_ID=stations.Building_ID AND resolutions.Resolution_ID = incident_sheet.Resolution_ID AND assign_groups.Group_ID = incident_sheet.Group_ID AND customer.Customer_ID = ($_POST[Criteria]);"; 

$result = mysql_query($sql, $con); 

while($row = mysql_fetch_array($result)) 
{ 
$Ticket_ID = $row['Ticket_ID']; 

echo 
} 
} 
if(IsChecked('formDoor[]','Last_Name')) 
{ $select_query = "select I.Ticket_ID, I.Customer_ID, I.Description, I.Date, C.Station_ID, C.First_Name, C.Last_Name, C.Phone_num, C.Email, S.Building_ID, S.Floor_ID, S.Room_ID, B.Location, A.Assign_Groups, R.Resolutions; 
from incident_sheet I, customer C, stations S, building B, assign_groups A, resoultions R; 
where I.Customer_ID = C.Customer_ID, 
and C.Station_ID = S.Station_ID, 
and S.Building_ID = B.Building_ID, 
and I.Group_ID = A.Group_ID, 
and I.Resoultion_ID = R.Resoultion_ID, 
order by Last_Name;" 
} 
if(IsChecked('formDoor[]','Station_ID')) 
{ $select_query = "select I.Ticket_ID, I.Customer_ID, I.Description, I.Date, C.Station_ID, C.First_Name, C.Last_Name, C.Phone_num, C.Email, S.Building_ID, S.Floor_ID, S.Room_ID, B.Location, A.Assign_Groups, R.Resolutions; 
from incident_sheet I, customer C, stations S, building B, assign_groups A, resoultions R; 
where I.Customer_ID = C.Customer_ID, 
and C.Station_ID = S.Station_ID, 
and S.Building_ID = B.Building_ID, 
and I.Group_ID = A.Group_ID, 
and I.Resoultion_ID = R.Resoultion_ID, 
order by Station_ID;" 
} 
if(IsChecked('formDoor[]','Date')) 
{ $select_query = "select I.Ticket_ID, I.Customer_ID, I.Description, I.Date, C.Station_ID, C.First_Name, C.Last_Name, C.Phone_num, C.Email, S.Building_ID, S.Floor_ID, S.Room_ID, B.Location, A.Assign_Groups, R.Resolutions; 
from incident_sheet I, customer C, stations S, building B, assign_groups A, resoultions R; 
where I.Customer_ID = C.Customer_ID, 
and C.Station_ID = S.Station_ID, 
and S.Building_ID = B.Building_ID, 
and I.Group_ID = A.Group_ID, 
and I.Resoultion_ID = R.Resoultion_ID, 
order by Date;" 
} 
if(IsChecked('formDoor[]','Description')) 
{ $select_query = "select I.Ticket_ID, I.Customer_ID, I.Description, I.Date, C.Station_ID, C.First_Name, C.Last_Name, C.Phone_num, C.Email, S.Building_ID, S.Floor_ID, S.Room_ID, B.Location, A.Assign_Groups, R.Resolutions; 
from incident_sheet I, customer C, stations S, building B, assign_groups A, resoultions R; 
where I.Customer_ID = C.Customer_ID, 
and C.Station_ID = S.Station_ID, 
and S.Building_ID = B.Building_ID, 
and I.Group_ID = A.Group_ID, 
and I.Resoultion_ID = R.Resoultion_ID, 
order by Description;" 
} 
?> 
<h3>This is the current ticket information: </h3> 
    <p> 

    <table> 
     <tr> 
     <td>First Name:</td> 
     <td><?php echo ("$First_Name"); ?></td> 
     </tr> 
     <tr> 
      <td>Last Name:</td> 
      <td><?php echo "$Last_Name"; ?></td> 
     </tr> 
     <tr> 
      <td>Email:</td> 
      <td><?php echo "$Email"; ?></td> 
     </tr> 
     <tr> 
      <td>Phone Number:</td> 
      <td><?php echo "$Phone_Num"; ?></td> 
     </tr> 
     <tr> 
      <td>Building:</td> 
      <td><?php echo "$Building_ID"; ?></td> 
     </tr> 
     <tr> 
      <td>Floor:</td> 
      <td><?php echo "$Floor_ID"; ?></td> 
     </tr> 
     <tr> 
      <td>Room:</td> 
      <td><?php echo "$Room_ID"; ?></td> 
     </tr> 
     <tr> 
      <td>Group:</td> 
      <td><?php echo "$Group_ID"; ?></td> 
     </tr> 
     <tr> 
      <td>Description:</td> 
      <td><?php echo "$Description"; ?></td> 
     </tr> 

    </table> 

    </p> 
    </body> 
    </html> 

在得到這個工作,將超過高度讚賞任何幫助,感謝您抽出時間來看看在此。

+4

這是[SQL注入漏洞](http://bobby-tables.com/php),因爲你是不使用適當的SQL轉義。你不應該在新的應用程序中使用mysql_query,而應該使用mysqli或PDO。至少應該使用'mysql_real_escape_string'來正確編碼你的值。 – tadman

+2

你有什麼問題?你有沒有空白的屏幕?錯誤消息?沒有錯誤信息,但沒有插入?插入的東西,但不是你所期望的? – andrewsi

+0

mysql已棄用,請使用mysqli –

回答

1

你沒有忘記定義這個值,對吧?沒有顯示調試信息的服務器不會顯示任何東西(500錯誤頁面可能)

DEFINE('DB_USER',<something>); 
DEFINE('DB_PASSWORD',<something>); 
DEFINE('DB_NAME',<something>); 
DEFINE('DB_HOST','localhost');