+ -
当前位置:首页 → 问答吧 → 不行还的求助版主或者各位前辈指点下小弟!

不行还的求助版主或者各位前辈指点下小弟!

时间:2010-10-06

来源:互联网

复制代码
  1. if (!function_exists("GetSQLValueString")) {
  2. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  3. {
  4.   if (PHP_VERSION < 6) {
  5.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  6.   }
  7.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  8.   switch ($theType) {
  9.     case "text":
  10.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  11.       break;   
  12.     case "long":
  13.     case "int":
  14.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  15.       break;
  16.     case "double":
  17.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  18.       break;
  19.     case "date":
  20.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  21.       break;
  22.     case "defined":
  23.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  24.       break;
  25.   }
  26.   return $theValue;
  27. }
  28. }
  29. $colname_Recordset1 = "Request('uname')";
  30. if (isset($_GET['uname'])) {
  31.   $colname_Recordset1 = $_GET['uname'];
  32. }
  33. mysql_select_db($database_conn, $conn);
  34. $query_Recordset1 = sprintf("SELECT * FROM userbiao WHERE uname like %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
  35. $Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
  36. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  37. $totalRows_Recordset1 = mysql_num_rows($Recordset1);


这是我写的后台按照会员帐户搜索会员的页面代码!    可是能搜索但是搜索出来不显示会员帐户,其他的信息都显示!   请教下代码那里又不对了嘛!  晕呼呼滴!


'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge">

'700')this.width='700';if(this.offsetHeight>'700')this.height='700';" title="Click Here To EnLarge"> 我后来改了请求的变量!
代码如下
<?php require_once('../Connections/conn.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;
}
}
$colname_Recordset1 = "1";
if (isset($_GET['uname'])) {
  $colname_Recordset1 = $_GET['uname'];
}
mysql_select_db($database_conn, $conn);
$query_Recordset1 = sprintf("SELECT * FROM userbiao WHERE uname like %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>



 之前的是$colname_Recordset1 = "Request('uname')";    
把这个改为了$colname_Recordset1 = "1"; 
然后可以搜索 但是只输入任何帐户  他就只显示和1有关联的帐户信息!

请教怎么回事哦!   那个值改如何写才正确呢!

[ 此帖被yk19880829在2010-10-06 18:36重新编辑 ]

作者: yk19880829   发布时间: 2010-10-06

你可以把值一个个打印出来看看,首先打印下$colname_Recordset1 ,在sql语句前和赋值后打印。然后再把这个的值打印看看,这样就可以GetSQLValueString("%" . $colname_Recordset1 . "%", "text") ,如果都没问题,最后打印下sql语句。这样一步一步下来应该能找到问题所在

作者: 刹那芳华网   发布时间: 2010-10-06