SQL错误1064不确定

时间:2013-09-01 08:52:31

标签: php mysql

我正在尝试一种将数据插入SQL的新方法。我收到此错误

insert into tracking_clients set /   agreement_type = 'Purchase' , existing_client = 'Yes' , 
sales_rep = '1'
Array ( [agreement_type] => Purchase [existing_client] => Yes [sales_rep] => 1 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '/   agreement_type = 'Purchase' , 
existing_client = 'Yes' , sales_rep = ' at line 2mysql err no : 1064

我使用带有操作POST的表单

在我的提交页面中,我使用以下

//Drawn from Form Information used to Update Database
$sub1 = $_REQUEST['agreement_type'];
$sub2 = $_REQUEST['existing_client'];
$sub3 = $_REQUEST['sales_rep'];

update_lbs($sub1, $sub2, $sub3, $sub4,....); //Not full string posted here
function update_lbs($sub1, $sub2, $sub3, $sub4,.....)

{
  global $host;
  global $username;
  global $password;
  global $db_name;
  //Insert if dates is required
date_default_timezone_set('Africa/Johannesburg'); //Global Time one for South Africa
 $today = date("Y-m-d H:i:s");
$date = date("Y-m-d") ;
$time = date("H:i:s");
$insertSuccessful = false;
$new_msisdn = '0' . substr($msisdn, 2); //Not Sure If this is required in normal SET command
if ($con = mysql_connect($host, $username, $password)) {
    if (mysql_select_db($db_name))      
//First Database Insert change table name as required
        $sql = "insert into tracking_clients  set    
        agreement_type =  '".$sub1."' ,
        existing_client =  '".$sub2."' ,
        sales_rep = '".$sub3."',

                    sub_date = '".$date."'" //Last of the code for SET
        ;    
if (mysql_query($sql, $con)) {
            $insertSuccessful = true;
        } else {
            echo $sql;
            print_r($_POST);
            echo "\n" . mysql_error($con);
            echo "mysql err no : " . mysql_errno($con);
        }

我不确定会导致此错误的原因。我知道这个问题很常见,但是通过其他问题阅读我没有得到错误

2 个答案:

答案 0 :(得分:1)

“set”和“Agreement type”之间有一个制表符

答案 1 :(得分:1)

我假设你在这里使用mysql。 insert语句不使用set它只是插入值。

这样的事情:

insert into yourTable (val1, val2, val3)

insert into yourTable (col1, col2, col3) values (val1, val2, val3)

insert into yourTable set col1=val1 etc...