PHP回声问题

时间:2011-06-09 08:08:44

标签: php mysql

$today = date('D, d M, Y');
$sql = "SELECT * FROM programs 
        WHERE day1 = '$today' OR day2 = '$today' OR day3 = '$today' OR day4 = '$today' 
        OR day5 = '$today' OR day6 = '$today' OR day7 = '$today' OR day8 = '$today' 
        OR day9 = '$today' OR day10 = '$today'";
if($_POST != "") {
  $mydate = mysql_real_escape_string($_POST['datepicker']);
  if($mydate != "") {   
     $sql = "SELECT * FROM programs 
         WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' 
           OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' 
           OR day9 = '$mydate' OR day10 = '$mydate'";
  }
}

$mydate与日历合并....

我如何回复日期?

3 个答案:

答案 0 :(得分:5)

如果您使用双引号,您的$mydate会自动由PHP转换:您在查询结尾处错过了双引号:

$sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'";//Missing double quotes

答案 1 :(得分:3)

你忘了“在SQL查询中。

$today = date('D, d M, Y');
$sql = "SELECT * FROM programs WHERE day1 = '$today' OR day2 = '$today' OR day3 = '$today' OR day4 = '$today' OR day5 = '$today' OR day6 = '$today' OR day7 = '$today' OR day8 = '$today' OR day9 = '$today' OR day10 = '$today'";

if($_POST!=""){
$mydate = mysql_real_escape_string($_POST['datepicker']);
    if($mydate!=""){    
    $sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'";
}
}

答案 2 :(得分:0)

你忘记使用双引号它应该是这个$sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'";