1
$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 is incorporated with a calendar....

How I php echo the date?

2
  • 3
    May be worth a mention that you forgot to close double quotes on line 2. Commented Jun 9, 2011 at 8:10
  • Perhaps it's also time to read a little something about database normalisation, it's almost never a good idea to have numbered columns in a table; that reeks of denormalisation, which generally makes your life a lot harder. Commented Jun 9, 2011 at 9:00

3 Answers 3

5

Your $mydate is automatically converted by php if you use double quotes: you just missed a double quote at the end of the query:

$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
Sign up to request clarification or add additional context in comments.

Comments

3

You forgot " in sql query.

$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'";
}
}

Comments

0

you forgot to use double quotes it should belike this $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'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.