簡體   English   中英

PHP到MySQL選擇查詢不起作用

[英]Php to MySql select query not working

我正在嘗試獲取一個從數據庫檢索的php頁面,我是php的新手,我已經用google搜索過,但我只是沒有得到它。 我有一個鏈接到php的htm頁面,因為我試圖根據所選的復選框和在條件框中提交的信息返回一些數據。 到目前為止,這是我的工作,我一直在困惑一些查詢,以使它正常工作,因此,如果我只能讓一個工作,那么我就可以讓其余的工作做我想要的事情。 我知道我的代碼可能不符合標准,但這不是我的專業,我只是一個試圖使項目正常工作的學生。 請指導我正確的方向。

編輯:這是一個我有的學校項目,我必須使用他們在服務器上擁有的東西,這種情況下恰好是mysql。 我什么也沒回來,沒有錯誤或任何東西。 當我從htm頁面轉到php頁面時,沒有任何反應。 我只是想想,我可能只需要運行一個簡單的查詢就可以調試,以確保可以得到任何東西,然后從那里進行修改。 我從未使用過復選框,也從未運行過查詢,所以我不得不相信那是我的錯誤所在。 我所有的insert和update語句都可以在其他頁面上使用,但是select語句代碼並將其放入變量中的方式對我來說非常混亂。

我的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>

非常感謝您對此工作的任何幫助,感謝您抽出寶貴的時間對此進行研究。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM