我正在运行一个简单的PHP脚本来从远程SQL Server获取一些查询。我总共有3个查询,还有1个MySQL查询。第一个SQL Server查询工作正常,返回我期望的,然后返回到下一个$ orders。这里的脚本停止了。我的意思是没有进一步的输出呈现给浏览器,结果的视图源在PHP块开始之前停止,从$ orders查询开始。
我的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" /> <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>
谢谢!
答案 0 :(得分:2)
我知道这有点晚了,但我刚刚遇到同样的问题并找到了解决办法。
在我的情况下,当只有少量字段时,我只能使用*标志来指示所有字段。在任何具有大量字段的表(在我的情况下约为25)尝试返回所有字段将导致我的整个php脚本失败,没有像你的错误。我刚刚被迫手动指定字段。
希望这会有所帮助。
答案 1 :(得分:0)
为什么要求两次require('../assets/mssql_connect.php');
?尝试删除第二个要求,看看你从那里得到了什么。
答案 2 :(得分:0)
首先不要使用mysql函数,尝试chage到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