title: PHP Ajax Javascript scan
body: <p>Trying to do my first Ajax call. Users can upload a file to my server. I want to add the feature of scanning for nudity and not accepting if nudity is found. I found a javascript scanner nude.js that will scan pics for nudity. I comes with demos and all. I am trying to apply it to my site.</p>
  
  <pre><code>&lt;script type="text/javascript" src="nude.js"&gt;
  function CheckNude() {
      nude.load("pics/". &lt;?
          $q         = "select max(id) from $table";
          $result    = mysql_query($q);
          $resrow    = mysql_fetch_row($result);
          $id        = $resrow[0] + 1;
          $file      = $_FILES['file'];
          $file_name = $_FILES['file']['name'];
          $picextorg = substr($file_name, -3);
          $picext    = strtolower($picextorg);
          $picfile   = "pics/" . $id . "." . $picext;
          echo $picfile;
      ?&gt;);
      nude.scan(function (result) {
          if (!result) {
              nude = false;
          } else {
              nude = true;
          }
      });
      nude.load( &lt;? $_FILES['file']['tmp_name'] ?&gt; );
      nude.scan(function (result) {
          if (!result) {
              var nude = "false";
          } else {
              var nude = "true";
          }
      });
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              if (xmlhttp.responseText == true) {
                  alert("Nudity was found in your picture. Please try again.");
              }
          }
      }
      xmlhttp.open("GET", "new2.php?nude=" + nude, true);
      xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;tr&gt;
      &lt;td width="150"&gt;
          &amp;nbsp;
          &lt;!--&lt;INPUT type="image" name="search" src="../images/formbutton.gif" border="0" &gt;--&gt;      
      &lt;/td&gt;
      &lt;td width="119"&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td width="147"&gt;&amp;nbsp; &lt;button type='submit' name='submit' value='Submit'       onclick="CheckNude()"&gt;
          &lt;img src='../images/formbutton.gif' width='40' height='40' /&gt;        &lt;label&gt; 
          Submit photo&lt;/label&gt;
      &lt;/td&gt;
  </code></pre>
  
  <p>Here is the PHP:</p>
  
  <pre><code>$email    = $_POST['email'];
  $aim      = $_POST['aim'];
  $icq      = $_POST['icq'];
  $yahoo    = $_POST['yahoo'];
  $homepage = $_POST['homepage'];
  $myip     = $_POST['myip'];
  if (!$myip)
      $myip = $ip;
  $email2      = $_POST['email2'];
  $password    = $_POST['password'];
  $title       = $_POST['title'];
  $download    = $_POST['download'];
  $approved    = $_POST['approved'];
  $allowdelete = $_POST['allowdelete'];
  $author      = $_POST['author'];
  $facebook    = $_POST['facebook'];
  $piclink     = $_POST['piclink'];
  $domain      = $_POST['domain'];
  $option3     = $_POST['option3'];
  $secret      = $_POST['secret'];
  $q           = "insert into $table values('', '$email', '$aim', '$icq', '$yahoo', '$homepage',    '0', '0', '0', '0', '0', '0', '',   now(),'$myip','$email2','$password','$title','$download','$approved','$allowdelete','$autho     r','$facebook','$piclink','$domain','$option3','$secret')";
  $result = mysql_query($q) or die("Failed: $sql - " . mysql_error());
  $q      = "select max(id) from $table";
  $result = mysql_query($q);
  $resrow = mysql_fetch_row($result);
  $id     = $resrow[0];
  $file   = $_FILES['file']['name'];
  move_uploaded_file($_FILES['file']['tmp_name'], "pics/" . $id . "." . $picext);
  $picfile = $id . "." . $picext;
  $nude    = $_REQUEST['nude'];
  $alert   = "false";
  if ($nude === "false") {
      $q      = "update $table set picfile = '" . $id . "." . $picext . "' where id='$id'";
      $result = mysql_query($q);
      Header("Location: index.php?id=$id");
  }
  if ($nude === "true") {
      $alert  = "true";
      $q      = "delete from $table where id='$id'";
      $result = mysql_query($q);
      unlink("pics/" . $picfile);
      Header("Location: new2.php");
  }
  echo $alert;
  </code></pre>
  
  <p>My page just loads to a blank white page with this code. What am I doing wrong?</p>