title: PHP Javascript Mysql Insert
body: <p>I am trying to use java-script prompt to insert values into MySQL.  I have a html file and a php file.  </p>
  
  <p>The html files saved as <code>Test.html</code>:</p>
  
  <pre><code> &lt;button onclick="myFunction()"&gt;Create Project&lt;/button&gt;
  
  &lt;script&gt;
    function myFunction() {
        var project = prompt("Please enter project name");
        if (project != null &amp;&amp; project !="") {
            $.post("conn.php", { project : project });
        }
    }
    &lt;/script&gt;
  </code></pre>
  
  <p>The <code>conn.php</code>:</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "Password";
  $dbname = "db1";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  $proj = $_POST['project'];
  $sql = "INSERT INTO projects (project_name) VALUES ('$proj')";
  
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo "New record created successfully";
  } else {
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  ?&gt; 
  </code></pre>
  
  <p>The conn.php works perfectly and inserts values if I remove the post parameter.</p>
  
  <p>For example, instead of this:</p>
  
  <pre><code>$proj = $_POST['project'];
  $sql = "INSERT INTO projects (project_name) VALUES ('$proj')";
  </code></pre>
  
  <p>if i use:</p>
  
  <pre><code>$proj = "NewProject";
  $sql = "INSERT INTO projects (project_name) VALUES ('$proj')";
  </code></pre>
  
  <p><code>NewProject</code> gets inserted into the database.</p>
  
  <p>I am not sure if I am missing something in my index.html which is not posting the value in the prompt to php script.  I have tried <code>echo $_POST['project'];</code> instead of inserting into MySQL.  The echo is missing.</p>