簡體   English   中英

PHP從數組插入數據庫

[英]Php insert from Array to database

我正在將剪貼的鏈接插入到數據庫中,但是當我在數據庫中簽入時,自動增量記錄的數量是正確的,但是cado字段仍然為空。 當我在$results_urls[$separate_result]插入默認值“ test”時,記錄將被填充。 我做錯了什么

$separate_results = explode("<td class=\"image\">", $results_page);   // Expploding the results into separate parts into an array

// For each separate result, scrape the URL
foreach ($separate_results as $separate_result) {
    if ($separate_result != "") {
        $results_urls[] = "http://www.imdb.com" . scrape_between($separate_result, "href=\"", "\" title="); // Scraping the page ID number and appending to the IMDb URL - Adding this URL to our URL array
        $add = "INSERT INTO pourqui(
                   cado
               ) VALUES (
                  '$results_urls[$separate_result]'
               )";

        $result_add = mysql_query($add);
        if (!$result_add) {
            die("Database query failed: " . mysql_error()); 
        }
    }

使用{}從數組插入數據

$add = "INSERT INTO pourqui(cado) VALUES ('{$results_urls[$separate_result]}')";
                                           ^                               ^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM