1

私がやろうとしているのは、ただ 1 つのことだけです。

$embedCode = mysql_real_escape_string('<object width="270" height="227"><param name="movie" value="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="270" height="227"></embed></object>');

今書いたら…

echo 'CODE = ' . $embedCode;

私は...

CODE = 

何も...

考え?

編集:

わかりました、私の意図は $embedCode を出力することではなく、それをデータベースに挿入することですが、null 値を取得しています。私は賢いお尻になると思っていましたが、ここでの単純なアプローチで裏目に出ました。とにかく、要点は、mysql クエリを通過していないということです。

編集 2: wordpress の $wpdb オブジェクトを使用しています

function insert_video(){

    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "video_manager"; 

    $embedCode = mysql_real_escape_string('<object width="270" height="227"><param name="movie" value="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/pz-VWi5-tGA?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="270" height="227"></embed></object>');
    $title  = 'this is my title'; 
    $description = 'this is my description';

    $wpdb->insert( $table_name, array( 'title' => mysql_real_escape_string($title), 'embed_code' => $embedCode, 'description' => mysql_real_escape_string($description) ) );

}

function get_video_block($id){
    insert_video();
    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "video_manager";
    $query = "SELECT * FROM " . $table_name . " WHERE `index` = '$id'"; 
    $results = $wpdb->get_results($query, ARRAY_A);


    $results = $results[0];

    $returnString = $results['title'] . '<br>';
    $returnString .= $results['embed_code'] . '<br>';
    $returnString .= $results['description'] . '<br>';

    return $returnString;

}

結果を得る:

this is my title<br><br>this is my description<br>
4

1 に答える 1

1

あなたはあなたのhtmlを大丈夫に印刷しています。右クリックして、そこにあるはずのソースを見てください。

mysql_real_escape_stringは、html をエスケープするためのものではありません。

テーブル内の実際のデータを phpmyadmin で見るとどうなるでしょうか? そこにない場合、問題はそのデータを入力するときです。

わかりましたので、テーブルに書き込むときにエスケープしますが、そのデータをサニタイズするために何か他のものを使用しています^ strip_tagsのように? Strip_tags は、そのすべての html を削除します。

wpdb_Class がその html を消去している可能性はありますか?

ええ、codex.wordpress.org/Function_Reference/wpdb_Class を見ると、 $wpdb->query('query') だけで任意のクエリを実行できるので、それを挿入するだけです。それが機能する場合、あなたは修正されています。

于 2010-08-25T02:40:17.867 に答える