2011-06-15 29 views
1

我正在運行一個簡單的PHP腳本來從遠程SQL Server獲取一些查詢。我總共有3個查詢,還有1個MySQL查詢。第一個SQL Server查詢工作正常,返回我期望的內容,然後轉到下一個$ order。這裏劇本停止了。我的意思是沒有進一步的輸出呈現給瀏覽器,結果的視圖源僅停留在以$ orders查詢開始的PHP塊之前。SQL Server查詢查殺腳本 - 無錯誤(PHP)

我的apache日誌,error_logs或其他任何地方都沒有錯誤。我還爲mssql顯示了get_last_message,它什麼也沒有顯示。在第二個mssql_query()之後鍵入或回顯任何內容。不工作,腳本停止。沒有超時,加載非常快。我在SQL Server中手動運行相同的查詢,並返回結果。

幫助?

  <?php 

     // CHECK IF USER LOGGED IN 
     session_start(); 
     if ($_SESSION['loggedIn'] != "true") { 
      header("Location: /reps/"); 
     } 

     // GRAB DATABASE DETAILS 
     require('../assets/mssql_connect.php'); 
     require('../assets/connect.php'); 

     // SET GLOBAL REP VARIABLES 
     $rep = $_SESSION['name']; 
     $admin = $_SESSION['id']; 
     $customer = $_GET['id']; 
     $code = $_POST['Code']; 

     ?> 

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
      <link rel="stylesheet" type="text/css" href="../assets/css/dashstyles.css" /> 
      <script language="javascript" src="/reps/assets/js/formvalidation.js"></script> 
      <title>Reps Dashboard - <?php echo $rep; ?></title> 
     </head> 

     <body> 

     <?php 

     // GET HEADER INCLUDE 
     require('../assets/header.php'); 


     // BUILD QUERY USING ID TO GET FIELDS 
     $edit = mssql_query("SELECT * FROM Customers WHERE ID='$customer'") 
     or die(mssql_get_last_message()); 

      while ($row = mssql_fetch_array($edit)) { 
      $code = $row['Code']; 
      $name = $row['Name']; 
      $address = $row['Address'] . "<br />" . $row['Town'] . "<br/>" . $row['County'] . "<br />" . $row['Postcode']; 
      $phone = $row['Tel']; 
      $fax = $row['Fax']; 
      } 

     mssql_free_result($edit); 

     ?> 

      <div id="main"> 
      <p class="welcome">Customer Detail: <?php echo $name; ?></p><p class="backlink"><img src="../assets/images/icons/back_icon.png" alt="Back" />&nbsp;<a class="backlink" href="/reps/dashboard/">Back to dashboard</a></p> 
       <table class="data"> 
        <tr> 
         <td style="width:40%"> 
          <table class="data" style="width:100%"> 
           <tr class="theader"> 
            <td>Customer Details</td> 
           </tr> 
           <tr> 
            <td><p><b>Customer Code: </b><?php echo $code; ?></p> 
             <p><b>Address:</b><br /><?php echo $name . "<br />" . $address; ?></p> 
             <p><b>Tel: </b><?php echo $phone . "<br /><b>Fax: </b>" . $fax; ?></p> 
            </td> 
           </tr> 
          </table> 
         </td> 
         <td style="width:60%"> 
          <table class="data" style="width:100%"> 
           <tr class="theader"> 
            <td>Customer Orders History</td> 
           </tr> 
           <tr> 
            <td> 
     <?php 

     require('../assets/mssql_connect.php'); 

     // BUILD NEW QUERY FOR ORDERS 
     $orders = mssql_query("SELECT TOP 10 * FROM MainJobDetails WHERE InvoiceCustomerCode='$code'") 
     or die(mssql_get_last_message($orders)); 

     // CHECK FOR 0 RECORDS 
     if(mssql_num_rows($orders) == 0) { 
      echo "No previous orders found."; 
     } else { 

     //OUTPUT PREVIOUS ORDERS 
     echo "Last 10 Orders<br />"; 
     echo "<table class='orders'>"; 
     echo "<tr><td>Date</td><td>Job Number</td><td>Description</td><td>Status</td><td>Value</td></tr>"; 

     // ALTERNATE ROW COLOURS 
     $c = 0; 

      while ($row = mssql_fetch_array($orders)) { 

      $class = $c++ % 2 == 1 ? "odd" : "even"; 
      echo "<tr class='$class'><td>"; 
      echo $row['CreateDateTime']; 
      echo "</td><td>"; 
      echo $row['JobNo']; 
      echo "</td><td>"; 
      echo $row['JobDesc']; 
      echo "</td><td>"; 
      echo $row['Description']; 
      echo "</td><td>"; 
      echo $row['PriceEst']; 
      echo "</td></tr>"; 
      } 

     echo "</table>"; 

     } 

     mssql_free_result($orders); 

     ?> 
            </td> 
           </tr> 
          </table> 
         </td> 
        </tr> 
        <tr> 
         <td style="width:40%"> 
          <table class="data" style="width:100%"> 
           <tr class="theader"> 
            <td>Comments Log</td> 
           </tr> 
           <tr> 
            <td> 
     <?php 

     // GET CURRENT COMMENTS 
     $comments = mysql_query("SELECT * FROM comments WHERE customer_id='$customer' ORDER BY id DESC LIMIT 0,5") 
     or die(mysql_error()); 

     // CHECK FOR 0 COMMENTS 
     if(mysql_num_rows($comments) == 0) { 
      echo "<p>No comments about this customer.</p>"; 
     } 

     // LOOP THROUGH PREVIOUS COMMENTS 
     while ($row = mysql_fetch_array($comments)) { 
      echo "<p style='line-height:20px;'><b>" . $row['rep'] . "</b> <i>(" . $row['date'] . " at " . $row['time'] . ")</i><br />"; 
      echo $row['comment'] . "</p>"; 
     } 

     ?> 
            <form method="POST" name="comments" action="../assets/comment_post.php" onsubmit="return validateCForm();"> 
             <textarea rows="10" cols="45" name="comment_box"></textarea><br /> 
             <input type="hidden" name="comment_date" value="<?php echo date('d.m.Y'); ?>"> 
             <input type="hidden" name="comment_time" value="<?php echo date('H:i:s'); ?>"> 
             <input type="hidden" name="id" value="<?php echo $customer; ?>"> 
             <input type="hidden" name="rep" value="<?php echo $rep; ?>"><br /> 
             <input type="submit" class="search" name="submit" value="Post Comment"> 
            </form> 
            </td> 
           </tr> 
          </table> 
         </td> 
         <td style="width:60%"> 
          <table class="data" style="width:100%"> 
           <tr class="theader"> 
            <td>Customer Estimates History</td> 
           </tr> 
           <tr> 
            <td> 
     <?php 

     // BUILD NEW QUERY FOR QUOTES 
     $quotes = mssql_query("SELECT * FROM MainEstimateDetails WHERE CustomerRef = '$code' ORDER by EstimateDate DESC LIMIT 0,10") 
     or die (mssql_error()); 

     // CHECK FOR 0 QUOTES 
     if(mssql_num_rows($quotes) == 0) { 
      echo "No previous quotes found."; 
     } else { 

     // OUTPUT PREVIOUS ORDERS 
     echo "<table class='orders'>"; 
     echo "<tr><td>Date</td><td>Job Number</td><td>Description</td><td>Status</td><td>Value</td></tr>"; 

     // ALTERNATE ROW COLOURS 
     $c = 0; 

     while ($row = mssql_fetch_array($quotes)) { 

      $class = $c++ % 2 == 1 ? "odd" : "even"; 
      echo "<tr class='$class'><td>"; 
      echo $row['CreateDateTime']; 
      echo "</td><td>"; 
      echo $row['JobNo']; 
      echo "</td><td>"; 
      echo $row['JobDesc']; 
      echo "</td><td>"; 
      echo $row['description']; 
      echo "</td><td>"; 
      echo $row['PriceEst']; 
      echo "</td></tr>"; 
      } 

     echo "</table>"; 


     } 

     ?> 
            </td> 
           </tr> 
          </table> 
         </td> 
        </tr> 
       </table> 
      </div> 
     </body> 
     </html> 

謝謝!

+4

這是太多的代碼引用;請把它縮小到更合理的大小,以捕捉問題的本質;我們不需要知道你的元標籤來幫助解決這個問題。 – 2011-06-15 16:34:30

+1

打開PHP的'display_errors'和'error_log'選項。可能有消息,但沒有記錄到任何地方和/或隱藏。 – 2011-06-15 16:35:23

+1

(關於Paul Sonier的請求,請考慮這些指針:http://sscce.org/) – pinkgothic 2011-06-15 16:38:56

回答

0

爲什麼你需要兩次require('../assets/mssql_connect.php');?嘗試刪除第二個要求,並看看你從那裏得到什麼。

+0

我被告知要在另一個幫助論壇上做這個,不管有沒有,結果都一樣。此外,我認爲這是相關的包括所有代碼,因爲它是影響它的腳本中的其他地方。 – 2011-06-15 16:39:43

0

首先不使用mysql函數,嘗試chaq到mysqli對象或PDO。 二,逃避你的變數!!!!

$edit = mssql_query("SELECT * FROM Customers WHERE ID='$customer'"); 

$edit = mssql_query("SELECT * FROM Customers WHERE ID='" . mysql_real_escape_string($customer) . "'"); 

對於視圖的錯誤,可以使顯示,在php.ini:

display_errors = On 

或PHP代碼的腳本:

ini_set('display_errors', 'On'); 

並使用error_reporting管理wath錯誤顯示:

error_reporting (E_ALL); // For all 

如果是生產,而不是可以顯示錯誤,請嘗試洛這一點,從php.ini文件:

log_errors = On 
log_errors_max_len = 0 // For not limits 
error_log = /my/logfile.log 
+0

嗨,所有錯誤報告已啓用,但沒有錯誤正在打印/顯示,腳本只是「終止」使用更好的單詞。 – 2011-06-16 06:48:37

2

我知道這是一個有點晚,但我只是來翻過這個同樣的問題,有找到了解決辦法。

在我的情況下,我只能使用*標誌來指示有少量字段時的所有字段。在任何包含大量字段(我的情況下大約爲25)的表上嘗試返回所有字段將導致我的整個PHP腳本失敗,沒有像你的錯誤。我剛剛被迫現在手動指定字段。

希望這會有所幫助。

+0

雖然上述情況屬實,但真正的原因是由於我的數據庫返回了一個smalldatetime字段類型。這會導致mssql嚴重死亡。從那時起,我現在必須使用強制重新格式化這些字段。希望這有助於任何人在未來。 – 2011-11-07 12:20:07