title: Ajax/PHP: Updating a Database
body: <p>I am using Ajax with PHP to insert values taken from input into a table in phpmyadmin. I am working with camp, but I have a problem getting the value of input.</p>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;inscription client&lt;/title&gt;
      &lt;script &gt;
        function test() {
          r=document.getElementById('1');
          if (r.value.length !==9)
            document.getElementById('demo').innerHTML="verifer le mot de passe";
          else  document.getElementById('demo').innerHTML="";
        }
        //////////////////////////////////////////
        function ajouter()
        {
          var cin=document.getElementById("cin").value;
          var nom=document.getElementById("nom").value;
          var mot_de_passe=document.getElementById("mot_de_passe").value;
          var xmlhttp = new XMLHttpRequest();
  
          var url = "http://localhost/amir/inscrireClient.php?cin="+cin+"&amp;nom="+nom+"&amp;mot_de_passe="+mot_de_passe;
          xmlhttp.onreadystatechange=function() {
  
            if (this.readyState == 4 &amp;&amp; this.status == 200)
            {
  
              if(this.responseText =="ok")
              {
                document.getElementById("2").innerHTML ="it woeks !";
                document.getElementById("2").style.backgroundColor="green";
              }
              else{
                document.getElementById("2").innerHTML="no";
                document.getElementById("2").style.backgroundColor="red";
  
              }
            };
  
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
          }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
      &lt;input   id ="cin" type="number" name="cin" value="123654789"  onblur="test()" required  &gt;  
      &lt;p style="color: red"   id="demo"&gt;&lt;/p&gt; 
      &lt;input type="text" id="nom" name="nom" value="aaa" placeholder="donner votre nom" &gt;  &lt;br&gt; &lt;br&gt;
      &lt;input type="password" id="mot_de_passe" name="mot_de_passe" value="aaa" placeholder="donner votre mot de passe" required=&gt;  &lt;br&gt; &lt;br&gt;
      &lt;button type="submit" onclick="ajouter()"&gt;s'inscrire &lt;/button&gt; 
      &lt;p id="2" &gt;&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this the PHP file:</p>
  
  <pre><code>&lt;?php
  include 'param.php'; 
  header("Access-Control-Allow-Origin: *"); 
  
  
  $cin=$_GET['cin'];
  $nom=$_GET['nom'];
  $mot_de_passe=$_GET['mot_de_passe'];
  
  try
  {
  
    $bdd = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8', $user, $passwd);
    $bdd-&gt;exec("SET CHARACTER SET utf8");
  }
  
  catch(Exception $e)
  {
    die('Erreur : '.$e-&gt;getMessage());
  }
  $reponse = $bdd-&gt;exec( "insert into client(cin,nom,mot_de_passe) values ($cin,'$nom','$mot_de_passe')" );
  if ($reponse-&gt;rowCount()&gt;0) 
    echo "ok";
  else        echo "non";
  ?&gt;
  </code></pre>
  
  <p>It does not change in the database:
  <img src="https://i.stack.imgur.com/UH4IX.png" alt="alt text"></p>
  
  <p><a href="https://i.stack.imgur.com/MC4KM.png" rel="nofollow noreferrer">error</a></p>