2017-08-03 64 views
0

我收到該錯誤,正在處理WordPress後期更新如何解決該問題?更新記錄時出錯:您的SQL語法中有錯誤

[videojs_hls URL = 'http://mn-i.mncdn.com/foxtv_mobile/smil:foxtv.smil/playlist.m3u8?token=c31bfe38167986e4922c0394488c4bf69639aeaf47863c7b '自動播放=' 真']錯誤更新記錄:您的SQL語法錯誤;檢查對應於您MariaDB的服務器版本正確的語法在1號線

使用近「http://mn-i.mncdn.com/foxtv_mobile/smil:foxtv.smil/playlist.m3u8?token=c31bfe381」而我的代碼手冊:

$site_url = "http://site.com.tr/live"; 
$site = file_get_contents($site_url); 

preg_match('@src : \'(.*?)\',@si',$site,$token); 


$newcontent = "[videojs_hls url='$token[1]' autoplay='true']"; 
echo $newcontent; 

$servername = "localhost"; 
$username = "xxx"; 
$password = "xxx"; 
$dbname = "xxx"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

$sql = "UPDATE wp_posts SET post_content='$newcontent' WHERE ID=33"; 

if ($conn->query($sql) === TRUE) { 
    echo "Record updated successfully"; 
} else { 
    echo "Error updating record: " . $conn->error; 
} 

$conn->close(); 

回答

0

您在字符串中使用單引號,你正試圖插入數據庫。您需要轉義單引號,否則查詢將無效。

您可以使用mysqli_real_escape_string來轉義單引號。

請參見下面的用法:

$site_url = "http://site.com.tr/live"; 
$site = file_get_contents($site_url); 

preg_match('@src : \'(.*?)\',@si',$site,$token); 


$newcontent = "[videojs_hls url='$token[1]' autoplay='true']" 
echo $newcontent; 
$servername = "localhost"; 
$username = "xxx"; 
$password = "xxx"; 
$dbname = "xxx"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

$newcontent = mysqli_real_escape_string($conn, $newcontent); 
$sql = "UPDATE wp_posts SET post_content='$newcontent' WHERE ID=33"; 

if ($conn->query($sql) === TRUE) { 
    echo "Record updated successfully"; 
} else { 
    echo "Error updating record: " . $conn->error; 
} 

$conn->close(); 
+0

謝謝!解決了 –

相關問題