2013-03-23 66 views
0

我會用mysql來存儲與tinymce一起保存的新聞的路徑, 但是從代碼發佈新聞保存在文件夾中並沒有插入到DB中, 奇怪的是我沒有從MySQL獲取任何錯誤。 這裏是我的代碼,感謝和抱歉,形成我的英文不好:dTinymce,php不存儲數據到mysql

<?php 
/* 

Configuration file 
for write_post.php 


*/ 
include ('config_db.php'); 
$query = "INSERT into news (path,count) values ('$qry', '1')"; 
$qry = NULL; 
    $cat= $_POST['cat'] . "/"; 
    $newsTitel = isset($_POST['title']) ? $_POST['title'] : 'Untitled'; 
    $submitDate = date('Y-m-d g:i:s A'); 
    $newsContent = isset($_POST['newstext']) ? $_POST['newstext'] : 'No content'; 
    $qry = $cat.$_POST['title'].".txt"; 

    //$filename = date('YmdHis'); 
    $filename = $newsTitel; 
    $f = fopen($cat . $filename.".txt","w+");  
    fwrite($f,$newsTitel."\n"); 
    fwrite($f,$submitDate."\n"); 
    fwrite($f,$newsContent."\n"); 
    fclose($f); 
    //$post = $cat . $filename . ".txt"; 
    if($mysqli->query($query)){ 
     echo "<br/>"; 
     echo "News inserita con successo!"; 
    }else{ 
     echo "<br/>"; 
     echo "Errore\n" . $mysqli->error; 
    } 
    echo "<br/>"; 
    // Try to echo $variable to check if is correct, and is ok but don't go into db 
    echo $qry; 
?> 

回答

1

你準備準備$ QRY前變量$查詢。因此,請嘗試以下操作:

但是,請注意,您並未使用sprintf()和mysql_real_escape_string(),而是不使用mysqli變量替換,強烈建議這些變量替換爲避免數據庫注入。

<?php 
/* 

Configuration file 
for write_post.php 


*/ 
include ('config_db.php'); 
$qry = NULL; 
    $cat= $_POST['cat'] . "/"; 
    $newsTitel = isset($_POST['title']) ? $_POST['title'] : 'Untitled'; 
    $submitDate = date('Y-m-d g:i:s A'); 
    $newsContent = isset($_POST['newstext']) ? $_POST['newstext'] : 'No content'; 
    $qry = $cat.$_POST['title'].".txt"; 

    //$filename = date('YmdHis'); 
    $filename = $newsTitel; 
    $f = fopen($cat . $filename.".txt","w+");  
    fwrite($f,$newsTitel."\n"); 
    fwrite($f,$submitDate."\n"); 
    fwrite($f,$newsContent."\n"); 
    fclose($f); 
    //$post = $cat . $filename . ".txt"; 

    // preparing query here 
    $query = "INSERT into news (path,count) values ('$qry', '1')"; 

    if($mysqli->query($query)){ 
     echo "<br/>"; 
     echo "News inserita con successo!"; 
    }else{ 
     echo "<br/>"; 
     echo "Errore\n" . $mysqli->error; 
    } 
    echo "<br/>"; 
    // Try to echo $variable to check if is correct, and is ok but don't go into db 
    echo $qry; 
?> 
+0

It Work,thanks;) – starbuck 2013-03-23 15:20:13

+0

在這種情況下,請注意它也很有用!感謝您的反饋! – somnath 2013-03-23 15:23:09