1

我有一个 PHP 页面 (ship_info.php),显示来自数据库的特定船舶的信息。每艘船都按其唯一的 ship_id 排序。

我需要在页面上获取链接以按字母顺序转到上一艘或下一艘船。有人建议我使用一个单独的 php 文件(称为 gotoship.php)。所以目前我在上一个链接上有这个链接:

  <!--go to previous ship-->
  <div class="arrow_shipinfo_left">
  <a href="gotoship.php?action=previous&amp;current_ship_id=<?php echo $row_ship_image_info['ship_id']; ?>">
<img src="images/arrow_left.png" width="51" height="57" alt="back" border="none"/>
  </a>
  </div>

所以我最终得到了一个看起来像“gotoship.php?action=previous¤t_ship_id=7”的链接。我不能完全让 gotoship.php 工作,任何人都可以阐明我哪里出错了。目前我收到一个数组到字符串的转换错误。我需要链接到这样的页面(shipinfo.php?ship_id=7)

我的 gotoship.php 看起来像这样:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_ships, $ships);
$query_ships = "SELECT TOP 1        ships.ship_id FROM   ship_information  INNER   JOIN (         SELECT ship_name FROM ship_information WHERE ship_id = $_GET'current_ship_id'        ) As current_ship     ON ships.ship_name < current_ship.ship_name ORDER BY ships.ship_name ASC";
$ships = mysql_query($query_ships, $ships) or die(mysql_error());
$row_ships = mysql_fetch_assoc($ships);
$totalRows_ships = mysql_num_rows($ships);
echo $current_ship_id;
 echo "<br><br>";
?>
4

1 回答 1

1

这对 sql 注入开放。您应该阅读这意味着什么,您应该考虑切换到 pdo 或至少 mysqli。这个查询(只要查询本身是正确的)将根据 GET ( ?ship_id=[the id that goes here]) 中提供的 id 选择一艘船。

mysql_select_db($database_ships, $ships);
$query_ships = "
SELECT ships.ship_id
FROM ship_information
INNER JOIN (
    SELECT ship_name 
    FROM ship_information 
    WHERE ship_id = '$_GET[ship_id]')
    AS current_ship
    ON ships.ship_name < current_ship.ship_name 
ORDER BY ships.ship_name ASC";
$ships = mysql_query($query_ships, $ships) or die(mysql_error());
$row_ships = mysql_fetch_assoc($ships);
$totalRows_ships = mysql_num_rows($ships);
echo $current_ship_id;
echo "<br><br>";
于 2013-07-09T09:35:58.810 回答