繁体   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