title: Failed to run query: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'
body: <p>I'm using PDO's  to connect to a Microsoft Server running in azure and I keep receiving the error:</p>
  
  <p>This is the function that I've written (insertUser):</p>
  
  <pre><code>private function generateSalt()
  {
      return dechex(mt_rand(0, 4453456454)) . dechex(mt_rand(0, 543545435));
  }
  
  private function hashPassword($originalPassword, $salt)
  {
      for($round = 0; $round &lt; 65536; $round++)
      {
          $password = hash('sha256', $password . $salt);
      }
  
      return $password;
  }
  
  private function insertUser()
  {
      $salt = $this-&gt;generateSalt();
      $password = $this-&gt;hashPassword($_POST['password'], $salt);
  
      $query = "INSERT INTO dbo.[User]
                              ( Title ,
                                FirstName ,
                                MiddleName ,
                                LastName ,
                                Gender ,
                                DOB ,
                                Email ,
                                Phone ,
                                Mobile ,
                                HomeAddress ,
                                HomePostCode ,
                                HomeSuburb ,
                                HomeState ,
                                HomeCountry ,
                                BrowserDetails ,
                                IsActive ,
                                Password ,
                                Salt ,
                                LastLogin ,
                                CompanyID ,
                                Created ,
                                CreatedBy ,
                                LastModified ,
                                LastModifiedBy ,
                                Username ,
                                UserRole
                              )
                      VALUES  ( @title , -- Title - varchar(50)
                                @firstname , -- FirstName - varchar(100)
                                @middlename , -- MiddleName - varchar(100)
                                @lastname , -- LastName - varchar(100)
                                @gender , -- Gender - varchar(20)
                                @dob , -- DOB - datetime
                                @email , -- Email - varchar(200)
                                @phone , -- Phone - varchar(50)
                                @mobile , -- Mobile - varchar(50)
                                @homeaddress , -- HomeAddress - varchar(100)
                                @homepostcode , -- HomePostCode - varchar(10)
                                @homesuburb , -- HomeSuburb - varchar(50)
                                @homestate , -- HomeState - varchar(20)
                                @homecountry , -- HomeCountry - varchar(200)
                                @browserdetails , -- BrowserDetails - varchar(500)
                                1 , -- IsActive - bit
                                @password , -- Password - varchar(500)
                                @salt , -- Salt - varchar(50)
                                GETDATE() , -- LastLogin - datetime
                                @companyid , -- CompanyID - int
                                GETDATE() , -- Created - datetime
                                user , -- CreatedBy - varchar(50)
                                NULL , -- LastModified - datetime
                                NULL , -- LastModifiedBy - varchar(50)
                                @username , -- Username - varchar(50)
                                'user'  -- UserRole - varchar(30)
                              )";
  
      $query_params = array(          ':title' =&gt; $_POST['title'] ,
                                      ':firstname' =&gt; $_POST['firstname'] ,
                                      ':middlename' =&gt; $_POST['middlename'] ,
                                      ':lastname' =&gt; $_POST['lastname'] ,
                                      ':gender' =&gt; $_POST['gender'] ,
                                      ':dob' =&gt; $_POST['dob'] ,
                                      ':email' =&gt; $_POST['email'] ,
                                      ':phone' =&gt; $_POST['phone'] ,
                                      ':mobile' =&gt; $_POST['mobile'] ,
                                      ':homeaddress' =&gt; $_POST['homeaddress'] ,
                                      ':homepostcode' =&gt; $_POST['homepostcode'] ,
                                      ':homesuburb' =&gt; $_POST['homesuburb'] ,
                                      ':homestate' =&gt; $_POST['homestate'] ,
                                      ':homecountry' =&gt; $_POST['homecountry'] ,
                                      ':browserdetails' =&gt; $_POST['browserdetails'] ,
                                      ':password' =&gt; $password ,
                                      ':salt' =&gt; $salt ,
                                      ':companyid' =&gt; $_POST['companyid'] ,
                                      ':username' =&gt; $_POST['username']   );
  
      try
      {
          $stmt = $this-&gt;db-&gt;prepare($query);
          $result = $stmt-&gt;execute($query_params);
      }
      catch(PDOException $ex)
      {
          die("Failed to run query: " . $ex-&gt;getMessage());
      }
  
      // display json encode on the page for AJAX to read
      echo json_encode(array('error' , $result));
  }
  </code></pre>
  
  <p>The error I'm receiving is this:</p>
  
  <blockquote>
    <p>Failed to run query: SQLSTATE[42000]: [Microsoft][SQL Server Native
    Client 11.0][SQL Server]Incorrect syntax near ')'.</p>
  </blockquote>
  
  <p>The reason this is confusing me so much is that I manually recreated the query in SQL Management Studio using the post data I was sending and everything worked properly. I've even  tried creating a temp table, and inserting there, but I'm still having no success. Help!</p>
  
  <p>For context, this is the post data I'm trying to use:</p>
  
  <p>category: 1</p>
  
  <ol start="2">
  <li>username: bhills_4993@veryrealemail.com</li>
  <li>companyemail: bhills_4993@veryrealemail.com</li>
  <li>confirmEmail: bhills_4993@veryrealemail.com</li>
  <li>password: 123</li>
  <li>confirmPassword: 123</li>
  <li>function: registrationProcessCompany</li>
  <li>category: workplace</li>
  <li>title: Ms</li>
  <li>firstname: Beverly</li>
  <li>lastname: Hills</li>
  <li>companyname: Hills Corp</li>
  <li>companysize: Hills Corp</li>
  <li>questdeptdiv: A specific department/division</li>
  <li>companyaddress: Hills Corp</li>
  <li>companysuburb: Hills Corp</li>
  <li>companypostcode: Hills Corp</li>
  <li>companytype: Information Media and Telecommunications</li>
  <li>SportingGroupAge[]: Senior</li>
  <li>statesportingbody: CA</li>
  <li>QuestAction: Eat healthily and drink less alcohol</li>
  <li>source: Radio</li>
  </ol>
  
  <p>And this is the table design:</p>
  
  <pre><code>USE [junglegymSQL] GO
  
  /****** Object:  Table [dbo].[User]    Script Date: 19/12/2013 8:28:32 PM ******/ SET ANSI_NULLS ON GO
  
  SET QUOTED_IDENTIFIER ON GO
  
  SET ANSI_PADDING ON GO
  
  CREATE TABLE [dbo].[User](
      [UserId] [int] IDENTITY(1,1) NOT NULL,  
      [Title] [varchar](50) NULL,     
      [FirstName] [varchar](100) NOT NULL,    
      [MiddleName] [varchar](100) NULL,   
      [LastName] [varchar](100) NOT NULL,     
      [Gender] [varchar](20) NULL,    
      [DOB] [datetime] NULL,  
      [Email] [varchar](200) NOT NULL,    
      [Phone] [varchar](50) NULL,     
      [Mobile] [varchar](50) NULL,    
      [HomeAddress] [varchar](100) NULL,  
      [HomePostCode] [varchar](10) NULL,  
      [HomeSuburb] [varchar](50) NULL,    
      [HomeState] [varchar](20) NULL,     
      [HomeCountry] [varchar](200) NULL,  
      [BrowserDetails] [varchar](500) NULL,   
      [IsActive] [bit] NULL,  
      [Password] [varchar](500) NOT NULL,     
      [Salt] [varchar](50) NOT NULL,  
      [LastLogin] [datetime] NULL,    
      [CompanyID] [int] NULL,     
      [Created] [datetime] NULL,  
      [CreatedBy] [varchar](50) NULL,     
      [LastModified] [datetime] NULL,     
      [LastModifiedBy] [varchar](50) NULL,    
      [Username] [varchar](50) NOT NULL,  
      [UserRole] [varchar](30) NULL,  
  CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED  (
  [UserId] ASC 
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) )
  
  GO
  
  SET ANSI_PADDING OFF GO
  
  ALTER TABLE [dbo].[User] ADD  DEFAULT ('User') FOR [UserRole] GO
  
  ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_Company] FOREIGN KEY([CompanyID]) REFERENCES [dbo].[Company] ([CompanyID]) GO
  
  ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_Company] GO
  </code></pre>