title: php query inside a <script>
body: <p>I have a project that i need a confirmation from the user first before the program executes fully.</p>
  
  <p>Here's the scenario:
  The user will pick a date from a datepicker and then the program will automatically fetch/ detect if that date already existing in the database.</p>
  
  <p>And if it's existing then it will prompt the user if he/she wants to overwrite it, and if it's true then the query will run.</p>
  
  <p>Here’s my code so far but it's not properly working:</p>
  
  <pre><code>$filter = mysql_query("SELECT * FROM tbl_productivity WHERE scheduleDate='2013-12-15'") or die(mysql_error());
   if(mysql_num_rows($filter)==0)
   {
           $query = mysql_query("SELECT sched.campaign, sched.cmsName, sched.team,   sched.scheduleDate, sched.scheduleInput,sched.scheduleInput,STR_TO_DATE(MID(sched.scheduleInput, 7, 7), '%h:%i %p') as sIn, STR_TO_DATE(MID(sched.scheduleInput, 1, 8), '%h:%i %p') as sIn2,STR_TO_DATE(MID(sched.scheduleInput, 9, 12), '%h:%i %p') as sIn3, cms.loginDate, MAX(cms.logoutDate) as logoutDates, team.auxDate, team.general,team.outbound, team.authorized, team.break, team.lunch, team.email, team.coaching, team.systemDown, team.miscellaneous, team.training, team.general + team.outbound + team.authorized + team.break + team.lunch + team.email + team.coaching + team.systemDown + team.miscellaneous + team.training as totalAux FROM tbl_employeeschedules sched  LEFT OUTER JOIN tbl_cmsloginout cms ON sched.cmsName = cms.agentName AND sched.scheduleDate = cms.loginDate LEFT OUTER JOIN tbl_auxupload team ON sched.cmsName=team.cmsName AND sched.scheduleDate=team.auxDate WHERE sched.scheduleDate='2013-12-15' GROUP BY sched.cmsName ORDER BY sched.team") or die(mysql_error()); 
   }
   else
   {
     echo "&lt;script&gt; 
          var ans = confirm('Data dated 2013-12-15 already existing, Do you want to overwrite it?');
          if(ans==true)
          {
              $query = mysql_query('SELECT sched.campaign, sched.cmsName, sched.team, sched.scheduleDate, sched.scheduleInput,sched.scheduleInput,STR_TO_DATE(MID(sched.scheduleInput, 7, 7), '%h:%i %p') as sIn, STR_TO_DATE(MID(sched.scheduleInput, 1, 8), '%h:%i %p') as sIn2,STR_TO_DATE(MID(sched.scheduleInput, 9, 12), '%h:%i %p') as sIn3, cms.loginDate, MAX(cms.logoutDate) as logoutDates, team.auxDate, team.general,team.outbound, team.authorized, team.break, team.lunch, team.email, team.coaching, team.systemDown, team.miscellaneous, team.training, team.general + team.outbound + team.authorized + team.break + team.lunch + team.email + team.coaching + team.systemDown + team.miscellaneous + team.training as totalAux FROM tbl_employeeschedules sched  LEFT OUTER JOIN tbl_cmsloginout cms ON sched.cmsName = cms.agentName AND sched.scheduleDate = cms.loginDate LEFT OUTER JOIN tbl_auxupload team ON sched.cmsName=team.cmsName AND sched.scheduleDate=team.auxDate WHERE sched.scheduleDate='2013-12-15' GROUP BY sched.cmsName ORDER BY sched.team') or die(mysql_error());    
  
          }
      &lt;/script&gt;";
  </code></pre>
  
  <p>}</p>
  
  <p>There's no alert happening when I did this code. </p>