# Error:You have an error in your SQL syntax;

**URL:** https://forum.kirupa.com/t/error-you-have-an-error-in-your-sql-syntax/331131
**Category:** programming
**Created:** [May 24, 2013, 12:22am UTC](https://forum.kirupa.com/t/error-you-have-an-error-in-your-sql-syntax/331131 "2013-05-24T00:22:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![alpharaven](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@alpharaven](https://forum.kirupa.com/u/alpharaven)
#### Post date: [May 24, 2013, 12:22am UTC](https://forum.kirupa.com/t/error-you-have-an-error-in-your-sql-syntax/331131/1 "2013-05-24T00:22:38Z")

</div>

I have been trying for day to figure this out but I keep going around in circles. I am using an array to insert data into a mysql db.

```php

    $mainrow=array("jobNum","date_added","type","title","startDate","salary","location","desc","agent","phone","email");
addInfo($currentPage,$mainrow,"index.php",$labels);

public function addInfo( $table , $rows, $page,$rowheaders )
    {
        $output='<div class="post">';
        $i = 0;
        
        $field = array();
        $values = array();
        foreach ( $rows as $value ) 
        {
            array_push($values,"'".$_POST[$value."txt"]."'");
            array_push($field,$value);
        }
        $nvalues= implode(', ',$values);
        $fields= implode(', ',$field);
        
        if (isset($_POST['submitted']))
        {
                $insert = "INSERT INTO $table($fields) VALUES ($nvalues)";
                $add_member = mysql_query($insert);
                $msg = "You have successfully added an entry<br>";
            // //echo "<meta http-equiv='refresh' content='2; URL=".$page."'>";
                
                if (!mysql_query($insert))
                {
                  die('Error:' . mysql_error());
                  error_reporting(E_ALL);
                }
                else
                {
                    echo $msg;
                }
                
                mysql_close($con);

        } 
        }

```

Someone PLEASE HELP
