title: PHP code not inserting data into MySQL Database
body: <p>Basically i've been scratching my head at this and I still can't figure out why it's not inserting.</p>
  
  <p>I'm 100% sure the database is connected as it's fetching information just fine, however the following code fails to insert anything into the database. I've checked for spelling mistakes, i've checked from deprecated php code etc, and have used mysqli and mysql.</p>
  
  <pre><code>&lt;?php 
  
  include_once "settings.php";
  
  
  if (isset($_POST['sendMessage']) &amp;&amp; isset($_POST['messageTo']) &amp;&amp; isset($_POST['messageBody'])){
  
      $messageTo = mysql_real_escape_string($_POST['messageTo']);
      $messageBody = mysql_real_escape_string($_POST['messageBody']);
  
      $query= "INSERT INTO inbox (`msgTo`, `msgFrom`, `msgBody`)
           VALUES('$messageTo', '$username', '$messageBody')";
  
      if(mysql_query($query))
          echo "done.";
      else
          echo "Problem with Query";
  }
  ?&gt;
              &lt;form method="POST"&gt;
  
          &lt;div class="searchContain"&gt;
            &lt;input name="textfield" type="text" name="messageTo" class="input search"&gt;&lt;br /&gt;
  
            &lt;textarea placeholder="Your message..." name="messageBody" class="input sendmsg" &gt;&lt;/textarea&gt;&lt;br /&gt;
  
            &lt;button class="input" name="sendMessage"&gt;Send Message&lt;/button&gt;
          &lt;/div&gt;
  
          &lt;/form&gt; 
  </code></pre>
  
  <p>Settings.php:</p>
  
  <pre><code>&lt;?php 
  session_start();
  include_once "../more/config/connect.php";
  // Settings //
  
  
  function logincheck(){
  if (!isset($_SESSION['username'])){
      header("location: ../index.php");
  }
  }
  
  logincheck();
  
  $username=$_SESSION['username'];
  
  $gatherInfo=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1");
  $fetch=mysql_fetch_object($gatherInfo);
  
  ?&gt;
  </code></pre>
  
  <p>connect.php:</p>
  
  <pre><code>&lt;?php 
  
  // Connect to the server //
  date_default_timezone_set('Europe/London');
  mysql_connect("localhost", "root", "connected") or die (mysql_error ());
  
  mysql_select_db("ts") or die(mysql_error());
  ?&gt;
  </code></pre>
  
  <p>If anyone could help me fix this rather basic rookie error I'd be very grateful!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Basically after changing the code. I've gone through the MAMP panel and changed the errors so they display. It's giving me the following error message:</p>
  
  <blockquote>
    <p>Warning: mysql_connect(): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)</p>
  </blockquote>
  
  <p>in I've never come across this error before, any ideas? It seems to fetch data from the database just fine, so I'm not sure why.</p>