title: PHP - Add Script
body: <p>I'm quite new with PHP and need help coding an add script for my web site. I have coded the delete and update side and they are working perfectly. Basically, on secdtions of my web site you can add values to several text boxes and what I want is that when you click on 'Add' this will add the details from the textboxes to the database. To do this I am using PHP, Jquery and Ajax.</p>
  
  <p>This is the code I have for the update script:</p>
  
  <pre><code>public function update($tableName,$fieldArray,$fieldValues,$rowId,$updateCondition)
  {
      // Get PDO handle
      $PDO = new SQL();
      $dbh = $PDO-&gt;connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
  
      // Build query
      $this-&gt;sql = 'UPDATE '.$tableName.' SET ';
  
      $fieldCount = count($fieldArray);
  
      for ($i = 0; $i &lt; $fieldCount; $i++){
  
          // If the index is at the last field...
          $lastRow = $fieldCount - 1;
  
          if ($i != $lastRow) {
  
              // Add a comma
              $this-&gt;sql .= $fieldArray[$i].'=:'.$fieldArray[$i].', ';
  
          } else {
  
              // Dont add a comma
              $this-&gt;sql .= $fieldArray[$i].'=:'.$fieldArray[$i].' ';
  
          }
  
      }
  
      // If row id is null (if we don't know the row id)...
      if ($rowId == null || $rowId == "null") {
  
          // Then use the update condition in it's place
          $this-&gt;sql .= 'WHERE '.$updateCondition.' ';
  
      } else {
  
          // Use the ID
          $this-&gt;sql .= 'WHERE Id = '.$rowId.' ';
  
      }
  
  
  
      try {
  
          // Query
          $stmt = $dbh-&gt;prepare($this-&gt;sql);
  
          // Bind parameters
          for ($i = 0; $i &lt; $fieldCount; $i++){
  
              $stmt-&gt;bindParam(':'.$fieldArray[$i].'', $fieldValues[$i]);
  
          }
  
          $stmt-&gt;execute();
  
          $count = $stmt-&gt;rowCount();
  
          echo $count.' row(s) affected by SQL: '.$stmt-&gt;queryString;
  
  
          $stmt-&gt;closeCursor();
  
      }
  
      catch (PDOException $pe) {
          echo 'Error: ' .$pe-&gt;getMessage(). 'SQL: '.$stmt-&gt;queryString;
          die();
      }   
  
      // Close connection
      $dbh = null;
  }
  </code></pre>
  
  <p>This is the part I am struggling to code, if you look at the code I have used for my update script.. I basically need something similiar to use for my 'add' script.</p>
  
  <p>Any help will be much appreciated!!</p>