1

我正在尝试一种将数据插入 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);
        }

我不确定是什么导致了这个错误。我知道这个问题很常见,但是通过其他 awnsers 阅读我没有收到错误

4

2 回答 2

1

您在“set”和“agreement_type”之间有一个制表符

于 2013-09-01T08:56:33.460 回答
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...
于 2013-09-01T08:59:37.383 回答