2016-12-23 63 views
-1

Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\cc_real\3HLR14CMORCGZ0IY8AE7H4JL409RV9\insert.php on line 15.解析錯誤:語法錯誤,意外'「,希望標識符(T_STRING)或變量(T_VARIABLE)或數字(T_NUM_STRING)

顯示我這個錯誤,而下面是我的代碼,我嘗試使用插入數據到數據庫中。

<?php 
echo "Invoked!!!"; 

$con = mysqli_connect('localhost', 'root', ''); 
if (!$con) 
{ 
    die('could not connect:'.mysql_error());  
} 
mysqli_select_db('job1'); 


Error: $sql = "INSERT INTO `cc_job2`(cc_Answer_filename,cc_time,cc_workerID) VALUES 
     ('$_post["Answer_filename"]','$_post["track_data"]','$_post["workerID"]')"; 

$result = mysqli_query($sql) 
if ($result){ 
    echo ("<br> Input data is succeed") 
} else{ 
    echo("<br> Input data is failed"); 
} 
mysqli_close($con); 
?> 
+0

你的問題的語法高亮會給你一個線索。 – Federkun

+0

你只是忘記了關閉';'在某些行中,如 '$ result = mysqli_query($ sql)'和'echo(「
輸入數據成功」)' – Beginner

+0

** ** result = mysqli_query $ sql)和回聲(「
輸入數據成功」)**添加分號';' –

回答

0

只需添加行echo ("<br> Input data is succeed")$result = mysqli_query($sql);結束。

嘗試這樣的事情。

<?php 
echo "Invoked!!!"; 

$con = mysqli_connect('localhost', 'root', ''); 
if (!$con) 
{ 
die('could not connect:'.mysql_error());  
} 
mysqli_select_db('job1'); 


Error: $sql = "INSERT INTO cc_job2(cc_Answer_filename,cc_time,cc_workerID) VALUES ('".$_post['Answer_filename']."','".$_post['track_data']."','".$_post['workerID']."')"; 

$result = mysqli_query($sql); 
if ($result){ 
echo ("<br> Input data is succeed"); 

}else{ 
echo("<br> Input data is failed"); 
} 
mysqli_close($con); 
?> 
+0

我不認爲typeerror是可以接受的 – Beginner

+0

我已更新我的答案請檢查一次 –

+0

謝謝@PravinVavadiya –

0
$sql = "INSERT INTO `cc_job2`(cc_Answer_filename,cc_time,cc_workerID) VALUES ('".$_post['Answer_filename']."','".$_post['track_data']."','".$_post['workerID']."')"; 
+0

嘗試使用此語法 –

0

Concate在MySQL查詢:

<?php 
echo "Invoked!!!"; 

$con = mysqli_connect('localhost', 'root', ''); 
if (!$con) 
{ 
die('could not connect:'.mysql_error());  
} 
mysqli_select_db('job1'); 


Error: $sql = "INSERT INTO cc_job2 (cc_Answer_filename,cc_time,cc_workerID) VALUES 
     ('".$_post["Answer_filename"]."','".$_post["track_data"]."','".$_post["workerID"]."')"; 

$result = mysqli_query($sql) 
if ($result){ 
echo ("<br> Input data is succeed"); 

}else{ 
echo("<br> Input data is failed"); 
} 
mysqli_close($con); 
?> 
1

沒有與這段代碼的幾個問題。

  1. 在幾行
  2. 缺少對於大多數mysqli_功能$con參數到底缺少;
  3. 混合mysql_mysqli_
  4. 使用的$_post代替$_POST(大寫)

查看代碼中有關已更改內容的註釋。

<?php 
echo "Invoked!!!"; 

$con = mysqli_connect('localhost', 'root', ''); 
/* 
You can also do this, and drop mysqli_select_db() later in the code 
$con = mysqli_connect('localhost', 'root', '', 'job1'); 
*/ 

if (!$con) { 
    // Cannot mix mysql with mysqli (changed out mysql_error()) 
    // Also, mysqli has "mysqli_connect_error()" for connecting errors 
    die('could not connect: '.mysqli_connect_error());  
} 

// This function require the $con parameter 
mysqli_select_db($con, 'job1'); 

// Quotes being messed up - this is your current error 
// Concatenate the POST values instead, like this 
// Also using $_post instead of $_POST 
$sql = "INSERT INTO `cc_job2` (cc_Answer_filename, cc_time, cc_workerID) VALUES ('".$_POST["Answer_filename"]."', '".$_POST["track_data"]."', '".$_POST["workerID"]."')"; 

// Missing $con as the first parameter and ; at the end 
$result = mysqli_query($con, $sql); 
if ($result) { 
    // Missing ; at the end 
    echo "<br> Input data is succeed"; 
} else{ 
    echo "<br> Input data is failed"; 
    // You should add echo mysqli_error($con); here to troubleshoot queries 
} 
mysqli_close($con); 
?> 

注意查詢將如果任何POST值包含singlequotes ',失敗,所以你要麼逃避他們,或者更好的是,使用預準備語句(請參閱下面的段落和鏈接「我怎麼能防止SQL注入的PHP?」在底部。

這段代碼也容易受到SQL注入,你應該使用準備好的語句使用佔位符來保護自己免受此。

看到這些鏈接

相關問題