我浪费了一天几乎要解决这个问题但却无法找到解决方案。我被困在MSSQL程序与PHP。我有一个5个字段的形式,返回"金额"何时计算。该过程在SQl Managemant 2008上完美运行,但是从php代码执行时显示错误。请在我的代码和屏幕截图下方帮助我。
<div id="middle_pane">
<div>
<div id="inner_pane">
<div id="center_pane">
<div id="center_inner_pane">
<div class="txt_content">
<table width="385" height="200" style=" border:2px solid silver" cellpadding="6px" cellspacing="0px" align="center" border="0">
<form method="POST" action="<?php bloginfo('url');?>/fedex-tariff">
<tr>
<td colspan="2" style="background:#0066FF; color:#FFFFFF; fontsize:50px">Fedex Rate Card</td></tr>
<tr>
<td>Origin</td>
<td>
<select name="origin" id="origin" onChange="">
<option value="pakistan">Pakistan</option>
</select>
</td>
</tr>
<tr>
<td>Select Origin city </td>
<td>
<select name="city_id" id="city_id">
<option value="">--SELECT CITY--</option>
<?php
$city = "select * from branches";
$city_query = mssql_query($city);
while ($row_city = mssql_fetch_array($city_query)){
?>
<option value="<?php echo $row_city['zoneCode'];?>"> <?php echo $row_city['name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select Destination </td>
<td>
<select name="country_id" id="country_id">
<option value="">--SELECT Destination--</option>
<?php
$service= "select * from country";
$service_query= mssql_query($service);
while ($row_service = mssql_fetch_array($service_query)){
?>
<option value="<?php echo $row_service['Code'];?>"> <?php echo $row_service['Name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> Selection of Weight </td>
<td>
<div id="wgt">
<input type="text" id="weight" name="weight" value="" placeholder="weight...." required="">
</div>
</td>
</tr>
<tr>
<td>Select Your Service</td>
<td>
<select name="service_id" id="service_id">
<option value="">--SELECT--</option>
<?php
$service_type = "SELECT distinct ServiceTypeId from dbo.IntlZoneCountry where ServiceTypeId IN ('FedEx Cash Tariff Docs','FedEx Box','FedEx Student Package')";
$res_type = mssql_query($service_type);
$cnt_type = mssql_num_rows($res_type);
while($row_type = mssql_fetch_array($res_type)){
?>
<option value="<?php echo $row_type['ServiceTypeId'];?>"><?php echo $row_type['ServiceTypeId'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> <input type="submit" value="Calculate" name="submit" class="btn"></td>
</tr>
</form>
<table width="385" style=" border:2px solid silver" cellpadding="6px" cellspacing="0px" align="center" border="0">
<tr>
<td>
<?php
if(isset($_POST['submit']))
{
$city_id = $_POST['city_id'];
$country_id = $_POST['country_id'];
$service_id = $_POST['service_id'];
$weight_id = $_POST['weight'];
//This is PHP validation
if(empty($city_id) || empty($country_id) || empty($service_id) || empty($weight_id)){
?><center><?php echo "Please filled all the fields first.";?></center>
<?php
}
else{
$tozoneCode = "Select ZoneCode from dbo.IntlZoneCountry where CountryCode= '$country_id' AND ServiceTypeId= '$service_id'";
$result_tozoneCode = mssql_query($tozoneCode,$conn);
while($row = mssql_fetch_assoc($result_tozoneCode)){
$toZone = $row['ZoneCode'];
}
$result = mssql_query('set ANSI_NULL_DFLT_ON ON',$conn);
$stmt = mssql_init('SP_UpdateCNPrice_Int_Tariff',$conn);
echo "<pre>";
print_r($stmt);
//$weight_id = '5';$city_id = '3';$toZone = 'D';$service_id = 'fedex';$gstPercent='12.2';
mssql_bind($stmt, '@weight', $weight_id, SQLVARCHAR);
mssql_bind($stmt, '@FromZone', $city_id, SQLVARCHAR);
mssql_bind($stmt, '@ToZone', $toZone, SQLVARCHAR);
mssql_bind($stmt, '@serviceType', $service_id, SQLVARCHAR);
// $outVar1 = '';
//$outVar2 = '';
// mssql_bind($stmt, '@amount', $outVar1, SQLVARCHAR);
//mssql_bind($stmt, '@gst', $outVar2, SQLVARCHAR);
//$proc_result = mssql_execute($stmt, true);
if ($proc_result = mssql_execute($stmt)){
while ($row = mssql_fetch_assoc($proc_result)){
echo $row["amount"];
}
}
die("<BR>".mssql_get_last_message());
//print($outVar1);
//print($outVar2);
mssql_close($conn);
// $proc = mssql_init("[SP_UpdateCNPrice_Int_Tariff] '$weight_id','$city_id','$toZone','$service_id'", $conn);
//$result = mssql_execute($proc);
//print_r($result);
/*while($row = mssql_fetch_assoc($result)){
//print_r($row);
?>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td>
<center>
<font size="3">
<?php
$val = $row['amount'];
$gst = $row['gst'];
echo "<strong>"."Rate : "."$".""." ".$val.$gst;
?>
</font>
</center>
</td>
</tr>
<tr style="background:#00CFFF; color:blue;">
<td><center> All Rates are Exclusive of 16% GST + 23% fuel Charges (FSC).</center> </td>
</tr>
<?php
}*/
}
}
// mssql_close();
?>
</table>
</div>
</br>
<font size="2"><center>For more details <strong><a href="http://ocs.com.pk/customer-care-2">Contact Us</a></strong> at any time.</center></font>
<div style="float:right;"></div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
我只是遇到了同样的问题。
我的PHP - &gt; MSSQL存储过程先前已正常工作,然后,某些在环境中发生了变化,突然间代码停止工作。
我改用了:
$proc = mssql_init('storedProceedureName', $connection );
mssql_execute($proc);
使用
mssql_query( 'EXEC storedProceedureName', $connection );
突然间它再次开始工作了。不太确定为什么会这样,但我不打算在口中看到礼物马。