gpt4 book ai didi

php - MySQL/PHP 中的记录集链接

转载 作者:行者123 更新时间:2023-11-29 00:28:55 25 4
gpt4 key购买 nike

我有一个 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&current_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>";
?>

最佳答案

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

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>";

关于php - MySQL/PHP 中的记录集链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17544438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com