title: Pass a string from ajax to PHP
body: <p>I'm simply trying to read in a field from a text box, pass the value via ajax to PHP and then store the data in a mysql table. The table is already set up and ready to go, all I need is to insert values. </p>
  
  <p>Here is my js file </p>
  
  <pre><code>    var address = $("input#email").val(); 
      //If submission is valid 
      if(submitForm == "true"){
          $.ajax({  
              url: "bin/process.php",  
              type: "POST",  
              data: {email: address},   
              success: function(response) {  
              $('#message').html(response); 
              }
          });  
          return false; 
      }
  </code></pre>
  
  <p>And then my PHP looks like this </p>
  
  <pre><code>    &lt;?php
  
         function process($email){
  
          //Connect to the database  
          $con = mysql_connect('localhost', 'root', '') ; 
          if(!$con){ 
            retun mysql_error();  
          }
  
          //Insert Data into the Table
          $sql = 'INSERT INTO Users(email) VALUES ('$email')' ; 
          $query = mysql_query($sql, $con) 
          if(!$query){
            return mysql_error();
          }
  
          return "Thank you for your submission!"; 
         }
  
         echo process(trim($_POST['email']));
       ?&gt;
  </code></pre>
  
  <p>Right now I am getting this error</p>
  
  <pre><code>Parse error: syntax error, unexpected T_STRING /opt/lampp/htdocs/mysite/bin/process.php on line 3
  </code></pre>
  
  <p>So it appears that I am not passing the address value correctly, but I cannot figure out why.  For reference I was following the instructions on this post: <a href="https://stackoverflow.com/questions/6804327/jquery-ajax-call-from-javascript-to-php">Jquery ajax call from javascript to PHP</a></p>
  
  <p>I don't quite understand the last echo line, but I tried multiple methods, and they all gave me the same error. </p>
  
  <p>Thanks in advance! </p>