gpt4 book ai didi

php - mysql 中的动态 php vars,sql- vars 得到设置,但结果集为空?

转载 作者:行者123 更新时间:2023-11-30 23:38:00 25 4
gpt4 key购买 nike

我有以下由其他人创建的代码,虽然看起来传递了变量,但结果集中没有返回任何内容;这一页: http://www.libraries.uc.edu/research/subject_resources/art/db/index.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;
}
}
if (isset($_GET['stval'])) {
$stval_Recordset1 = (get_magic_quotes_gpc()) ? $_Get['stval'] : addslashes($_Get['stval']);
}


if (isset($_GET['stval'])) {
$stval_Recordset1 = $_GET['stval'];
}

if (isset($_GET['sq'])) {
$sq_Recordset1 = $_GET['sq'];
}
mysql_select_db($database_daap_photo, $daap_photo);
$query_Recordset1 = sprintf("SELECT * FROM main WHERE %s = %s ", GetSQLValueString($stval_Recordset1, "text"),GetSQLValueString($sq_Recordset1, "text"));
$Recordset1 = mysql_query($query_limit_Recordset1, $daap_photo) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

?>

然后在正文中:

<?php  print_r($_GET);
if(isset($_GET["stval"])) echo "stval is set\n";
if(isset($_GET["sq"])) echo "sq is set\n";

?>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr bgcolor="#CCCCCC">
<td colspan="4" bgcolor="#FFFFFF"><h1>Art</h1>
<h2>Photography Images Slide Collection -Search Results </h2>
<p align="left" class="style1">Your search returned <strong></strong> records.<br />
|<br />
</p>
<p align="left" class="style1">Your search returned no results. Please
use your browsers back button to search again. </p>
<p>&nbsp;First | Previous | Next | Last<br />
<br />
</p></td>
<td bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr bgcolor="#CCCCCC">
<td bgcolor="#CCCCCC"><p><strong>Last Name </strong></p>
</td>
<td bgcolor="#CCCCCC"><strong>First Name </strong></td>
<td bgcolor="#CCCCCC"><strong>Dates</strong></td>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr bgcolor="#CCCCCC">
<td bgcolor="#FFFFFF">&nbsp;</td>
<td><strong>Nationality</strong></td>
<td><strong>Subject</strong></td>
<td><strong>Quantity</strong></td>
<td><strong>Media</strong></td>
</tr>
<?php do { ?>
<tr>
<td class="bold"><?php echo $row_Recordset1['LAST_NAME']; ?></td>
<td><?php echo $row_Recordset1['FIRST_NAME']; ?></td>
<td><?php echo $row_Recordset1['DATES']; ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

等....

谢谢!

最佳答案

尝试将查询更改为

SELECT * FROM main WHERE %s = '%s'

关于php - mysql 中的动态 php vars,sql- vars 得到设置,但结果集为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969297/

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