查看订单的问题

时间:2014-01-09 22:13:55

标签: php mysql

我创建了此代码,以便在提交到数据库后查看订单。 这个问题并不是一直发生,但有时我会遇到mysql错误。

并报告这些行

$FIRSTNAME=mysql_result($resultt,$it,"FIRSTNAME");
$LASTNAME=mysql_result($resultt,$it,"LASTNAME");
$EMAIL=mysql_result($resultt,$it,"EMAIL");
$PHONE=mysql_result($resultt,$it,"PHONE");
$ADDRESS1=mysql_result($resultt,$it,"ADDRESS1");
$ADDRESS2=mysql_result($resultt,$it,"ADDRESS2");
$CITY=mysql_result($resultt,$it,"CITY");
$STATE=mysql_result($resultt,$it,"STATE");

并非所有订购者都会收到此错误,但会弹出并阻止客户名称,并出现以下错误。

  

警告:mysql_result()[function.mysql-result]:无法跳转到第39行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第40行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第41行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第42行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第43行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第44行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第45行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

     

警告:mysql_result()[function.mysql-result]:无法跳转到第46行/home/florida/public_html/vieworder.php中MySQL结果索引3的第0行

谁能协助我告诉我我做错了什么?感谢

下面添加了更多代码:

<body>
<span class="TextC">
<?
$memberid = str_replace("'","''",$_REQUEST['ID']);  
date_default_timezone_set('America/New_York');
$dbh=mysql_connect ("localhost", "florida_fields", "fields321") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("florida_fields");

$queryt = "SELECT * FROM ORDERS WHERE OID = '$memberid' ";
$resultt = mysql_query($queryt) or die('Query failed: ' . mysql_error());

$numt=mysql_numrows($resultt);

$ORDERID=mysql_result($resultt,$it,"ORDERID");
$CART=mysql_result($resultt,$it,"CART");
$ORDERTOTAL=mysql_result($resultt,$it,"PRICE");
$CUSTOMER=mysql_result($resultt,$it,"CUSTOMER");
$PAYMETHOD=mysql_result($resultt,$it,"PAYMETHOD");
$PAID=mysql_result($resultt,$it,"PAID");
$MYPICKUP=mysql_result($resultt,$it,"PICKUPDATE");
$COMMENTS=mysql_result($resultt,$it,"COMMENTS");
$GRANDTOTAL=$ORDERTOTAL;



$queryt = "SELECT * FROM MEMBERS WHERE MID = '$CUSTOMER' ";
$resultt = mysql_query($queryt) or die('Query failed: ' . mysql_error());

$numt=mysql_numrows($resultt);

$FIRSTNAME=mysql_result($resultt,$it,"FIRSTNAME");
$LASTNAME=mysql_result($resultt,$it,"LASTNAME");
$EMAIL=mysql_result($resultt,$it,"EMAIL");
$PHONE=mysql_result($resultt,$it,"PHONE");
$ADDRESS1=mysql_result($resultt,$it,"ADDRESS1");
$ADDRESS2=mysql_result($resultt,$it,"ADDRESS2");
$CITY=mysql_result($resultt,$it,"CITY");
$STATE=mysql_result($resultt,$it,"STATE");



?>
<? echo $FIRSTNAME?><br />
<? echo $LASTNAME?><br />
<? echo $EMAIL?><br />
<? echo $PHONE?><br />
<? echo $ADDRESS1?><br />
<? echo $ADDRESS2?><br />
<? echo $CITY?><br />
<? echo $STATE?><br />
<br />
<br />
Pick-Up Date: <? echo $MYPICKUP?><br />
Order #: <? echo $ORDERID?><br /><br />
<? echo $CART?><br />

Comments: <? echo $COMMENTS?><br /><br />
Sub Total: $<? echo $GRANDTOTAL?><br />
<?php
$paypal = 'paypal';
$check = 'check';

if ($PAYMETHOD == "paypal")
{
    echo "Shipping & Handling = " . number_format(($GRANDTOTAL * .045), 2);
    $GRANDTOTAL = floatval(number_format(($GRANDTOTAL * 1.045), 2));
}
    elseif ($PAYMETHOD == "check")
{
    echo "Shipping & Handling = 0";
}
?><br />

Grand Total: $<? echo $GRANDTOTAL?><br />
Payment Method: <? echo $PAYMETHOD?></span><span class="TextB"><br />
<br />
<br />
<form>
<input type="button" class="TextA" onClick="window.print()" value="Print this page">
</form>
</span>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

最有可能的是,您的SELECT * FROM MEMBERS ...正在返回空集。您可以通过将代码包装在您访问结果的位置来防范:

if (numt>0){
    // work with results here.
}

根据您发布的代码,我无法确定您在$it的通话中使用mysql_result的位置。话虽如此,对于你正在做的事情,你不应该首先使用mysql_result

相反,你可以这样做:

$resultt = mysql_query($queryt) or die('Query failed: ' . mysql_error());
$numt=mysql_numrows($resultt);
if ($numt > 0){
    $row = mysql_fetch_assoc($resultt);
    $FIRSTNAME=$row["FIRSTNAME"];
    $LASTNAME=$row["LASTNAME"];
    $EMAIL=$row["EMAIL"];
    $PHONE=$row["PHONE"];
    // etc...
}

最后,您还应该考虑使用MySQLi,因为mysql_*函数已被弃用,并且还使用预处理语句来防止SQL注入。