Why can't I make a proper SQL/PHP query using javascript?
<p>I am trying to make a query to an SQL database and I can't figure out why my code won't work. When I call the javascript function:</p>

<pre><code>function calledfunction(){
var date = new Date(document.getElementById("datetime1").value);
var dateformat = "'"+date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() +":" + date.getMinutes()+"'";
        alert("Value is: " + dateformat);
                microAjax("genjsonphp.php?stdt="+dateformat, function(data) {
                     //edited out
      }
</code></pre>

<p>I get the alert: Value is: '2011-12-6 0:0'</p>

<p>When I copy the value in the alert and paste it so the above code becomes:</p>

<pre><code>function calledfunction(){
var date = new Date(document.getElementById("datetime1").value);
var dateformat = "'"+date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() +":" + date.getMinutes()+"'";
        alert("Value is: " + dateformat);
dateformat = '2011-12-6 0:0';

                microAjax("genjsonphp.php?stdt="+dateformat, function(data) {
                     //edited out
      }
</code></pre>

<p>Then the code works fine. Does anyone have an idea what is going wrong?</p>
