duangu1868 2013-07-24 15:43
浏览 23
已采纳

php mySQL返回一个空查询

I'm trying to create a billing history page where users can see a table with their purchase history in table format. I'm trying to add a link to each row so that users can see the full invoice details for each order.

When they click on the link (I've included the script for the overview page after this script) this script is supposed to execute the query but I'm just getting an empty message query.

Can anyone spot the error?

Thanks!!

Eugenie

<?php

include("mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");


$host="localhost"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="db"; // Database name 
$tbl_name="table"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$TicketID=$_GET['TicketID'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE TicketID='$TicketID'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);


// Get a specific result from the "example" table
$result = mysql_query($Sql) or die(mysql_error());


echo "<table width='100' border='1' cellpadding='0' cellspacing='0' id='records'>";
print "<h3 align='center'><strong>Billing History</strong></h3><p>";
echo "<tr>  
<th width='110' align='center'>Billing Date</th>
<th width='80' align='center'>Ticket #</th>  
<th align='center'>Project Title </th>
<th width='80' align='center'>Total GBP</th>



</tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr height='22' width='100' bordercolor='343434' align='center'><td>"; 
echo $row['date'];
echo "</td><td> "; 
echo $row['TicketID'];

echo "</td><td> "; 
echo $row['project'];
echo "</td><td> "; 
echo $row['grandTotal'];


} 

echo "</table>";

include(XOOPS_ROOT_PATH."/footer.php");

?>

This is the script that displays the full billing history and that contains the link with the script that executes the query (above).

<?php

include("mainfile.php");
include(XOOPS_ROOT_PATH."/header.php");


$host="localhost"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="db name"; // Database name 
$tbl_name="tbl name"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name  WHERE uid='";
$sql=$sql .  $xoopsUser->uid("s") . "'  AND Paid='Y'";


$result=mysql_query($sql);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>Billing Date</strong></td>
<td align="center"><strong>Invoice Number</strong></td>
<td align="center"><strong>Description</strong></td>
<td align="center"><strong>Total GBP</strong></td>
<td align="center"><strong>View</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['date']; ?></td>
<td><? echo $rows['TicketID']; ?></td>
<td><? echo $rows['project']; ?></td>
<td><? echo $rows['grandTotal']; ?></td>


<td align="center"><a href="http://website.co.uk/site/viewInvoice.php?TicketID=<? echo     $rows['TicketID']; ?>">View</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
include(XOOPS_ROOT_PATH."/footer.php");
?>    
  • 写回答

4条回答 默认 最新

  • dongqing4070 2013-07-24 15:55
    关注

    change this:

    // Get a specific result from the "example" table
    $result = mysql_query($Sql) or die(mysql_error());
    

    to this:

    $result = mysql_query($sql) or die(mysql_error());
    

    in viewInvoice.php but also look at the comments from other regarding security etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)