我是小溪,以下是我的代码,我已经仔细检查了表格,这些表格的拼写看起来是正确的,当我尝试将我提交给SQL时,我不断收到以下错误代码,< / p>
insert into lbs_trace_etrack set 27827910119, Trevor Ackermann, TEST, Elspark, Trevor,
1234, Trevor, on, Testing, lbs_msisdn = '27827910119', lbs_agent = 'Trevor Ackermann',
lbs_client = 'TEST', lbs_station = 'Elspark', lbs_io = 'Trevor', lbs_case = '1234',
lbs_for = 'Trevor', lbs_permision = 'on', lbs_type = 'Testing', lbs_date = '2013-11-
29', lbs_time = '14:44:59', lng = '', lat = '', distance = '', msisdn = '', result =
'', lbs_reason = ''Array ( [lbs_msisdn] => 27827910119 [lbs_agent] => Trevor Ackermann
[lbs_client] => TEST [lbs_station] => Elspark [lbs_io] => Trevor [lbs_case] => 1234
[lbs_for] => Trevor [lbs_permision] => on [lbs_type] => Testing [lbs_reason] =>
Testing site and the functions [lbs_submit] => Trace )
错误是:
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 '27827910119, Trevor Ackermann, TEST, Elspark, Trevor, 1234,
Trevor, on, Testing,' at line 2mysql err no : 1064
这是我的行动PHP
//database settings
$host = "localhost"; // Host name
$username = "stingin_epanic"; // Mysql username
$password = "*****"; // Mysql password
$db_name = "*****"; // Database name
//Drawn from Form Information used to Update Database
$lbs_msisdn = $_REQUEST['lbs_msisdn'];
$lbs_agent = $_REQUEST['lbs_agent'];
$lbs_client = $_REQUEST['lbs_client'];
$lbs_station = $_REQUEST['lbs_station'];
$lbs_io = $_REQUEST['lbs_io'];
$lbs_case = $_REQUEST['lbs_case'];
$lbs_for = $_REQUEST['lbs_for'];
$lbs_permision = $_REQUEST['lbs_permision'];
$lbs_type = $_REQUEST['lbs_type'];
$lbs_reason = $_REQUEST['lbs_reason'];
//update database
update_lbs($lbs_msisdn, $lbs_agent, $lbs_client, $lbs_station, $lbs_io, $lbs_case,
$lbs_for, $lbs_permision, $lbs_type, $lbs_reason);
function update_lbs($lbs_msisdn, $lbs_agent, $lbs_client, $lbs_station, $lbs_io,
$lbs_case, $lbs_for, $lbs_permision, $lbs_type, $lbs_reason)
global $host;
global $username;
global $password;
global $db_name;
date_default_timezone_set('Africa/Johannesburg');
$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);
if ($con = mysql_connect($host, $username, $password)) {
if (mysql_select_db($db_name)) {
$sql = "insert into lbs_trace_etrack set
lbs_msisdn = '".$lbs_msisdn."',
lbs_agent = '".$lbs_agent."',
lbs_client = '".$lbs_client."',
lbs_station = '".$lbs_station."',
lbs_io = '".$lbs_io."',
lbs_case = '".$lbs_case."',
lbs_for = '".$lbs_for."',
lbs_permision = '".$lbs_permision."',
lbs_type = '".$lbs_type."',
lbs_date = '".$date."',
lbs_time = '".$time."',
lng = '".$long."',
lat = '".$lat."',
distance = '".$dist."',
lbs_result = '".$response."',
lbs_reason = '".$lbs_reason."'"
;
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);
}
$sql1 = "insert into lbs_log set
lng = '".$long."',
lat = '".$lat."',
distance = '".$dist."',
lbs_msisdn = '".$lbs_msisdn."',
date_time = '".$today."',
result = '".$response."',
date = '".$date."',
lbs_agent = '".$lbs_agent."',
lbs_client = '".$lbs_client."'" ;
if (mysql_query($sql1, $con)) {
$insertSuccessful = true;
} else {
echo $sql1;
echo "\n" . mysql_error($con);
echo "mysql err no : " . mysql_errno($con);
}
}
$sql2 = "Update TEST_credits set credits=credits-1 Where account_nr=1";
if (mysql_query($sql2, $con)) {
$insertSuccessful = true;
} else {
echo $sql2;
echo "\n" . mysql_error($con);
echo "mysql err no : " . mysql_errno($con);
}
}
return $insertSuccessful;
}
sql给出了问题sql1和sql2字符串工作得很好
任何帮助表示赞赏
答案 0 :(得分:0)
您的语法不正确,请使用:
INSERT INTO table (col1, col2, ...) VALUES (val1, val2, ...)
或
INSERT INTO table SET col1 = val1,col2 = val2, ...
您缺少列名称。
注意:您的PHP代码与您提供的SQL语句不匹配。你能解释清楚吗?