Php 使用变量时无法回显选项卡值

Php 使用变量时无法回显选项卡值,php,mysql,Php,Mysql,我试着从我的表HK中比较两行。这是我的密码 <?php require_once('Connections/hk.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION <

我试着从我的表HK中比较两行。这是我的密码

<?php require_once('Connections/hk.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;
}
}

$month_1 = "-1";
if (isset($_GET['Month'])) {
    $month_1 = $_GET['Month'];
}

$year_1 = "-1";
if (isset($_GET['year'])) {
    $year_1 = $_GET['year'];
}

mysql_select_db($database_hk, $hk);
$query_Recordset1 = "SELECT * FROM inventory WHERE 'Month' = '.$month_1' AND 'year' = $year_1";
$Recordset1 = mysql_query($query_Recordset1, $hk) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


$month_2 = "-1";
if (isset($_GET['Month2'])) {
    $month_2 = $_GET['Month2'];
}

$year_2 = "-1";
if (isset($_GET['year2'])) {
    $year_2 = $_GET['year2'];
}


mysql_select_db($database_hk, $hk);
$query_Recordset2 = "SELECT * FROM inventory WHERE 'Month' = Month AND year = $year_2";
$Recordset2 = mysql_query($query_Recordset2, $hk) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

mysql_select_db($database_hk, $hk);
$query_Recordset3 = "SELECT * FROM inventory_month";
$Recordset3 = mysql_query($query_Recordset3, $hk) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);
?>
当我尝试时,我一无所获。我还用print\u r$\u GET检查了我的var; 我得到数组[Month1]=>12月[year1]=>2014年[Month2]=>1月[year2]=>2015年[submit]=>View

那么,如果设置了我的var,为什么它不响应月份和年份的更改

$query_Recordset1 = "SELECT * FROM inventory WHERE 'Month' = '.$month_1' AND 'year' = $year_1";


如果PHP_版本<6,您在哪里找到了测试代码{您的SQL查询有一个错误。您已经从'Month'='的目录中选择了*。$Month\u 1'和'year'=$year\u 1,它应该在哪里选择*从'Month'='$Month\u 1'和'year'=$year\u 1'的目录中选择了删除的注释。在$Month\u 1前面,您的第二个SQL查询还有一个错误,'Month'=Month,我认为您的意思是'Month'='Month\u 2'。您的GET请求有Month1和year1,但您的PHP正在查找月份和年份,这是第一个问题。我假设对于第二个查询,您按照我在上一篇评论中关于“Month”=“$Month_2”的建议进行了更新。@Turnerj感谢您的帮助,而不仅仅是告诉我用谷歌搜索它。它已经修复。现在是。$query_记录集1=sprintfSELECT*从库存中选择,其中月份=%s,年份=$year\u 1,GetSQLValueString$Month\u 1,文本,GetSQLValueString$year\u 1,文本;
$query_Recordset1 = sprintf("SELECT * FROM inventory WHERE Month = %s AND year = $year_1", GetSQLValueString($month_1, "text"), GetSQLValueString($year_1, "text"));
$query_Recordset2 = "SELECT * FROM inventory WHERE 'Month' = Month AND year = $year_2";
$query_Recordset2 = sprintf("SELECT * FROM inventory WHERE Month = %s AND year = $year_2", GetSQLValueString($month_2, "text"), GetSQLValueString($year_2, "text"));