php - 为什么我的 SQL 查询没有将数据放入数据库?

标签 php mysql

好的,我从网页中获取解析后的文本并将其放入名为 adtext 的列中。脚本运行没有错误,并说它把数据放在那里,但是当我手动检查行是空的!我在 return_ Between() 之后运行了 var_dump 并且文本在那里,但它没有进入数据库。这是到目前为止的代码...

mysqli_query($conn, $query1);

    $link_result = mysqli_query($conn, $query1);
    $result = mysqli_fetch_assoc($link_result);


    file_get_contents($result['adlink']);
    $text_holder = file_get_contents($result['adlink']);

    return_between($text_holder, "postingBody", "<!-- .posting -->", EXCL);
    $final_text = return_between($text_holder, "postingBody", "<!-- .posting -->", EXCL);

    $query2 = "UPDATE usedcars SET adtext = $final_text WHERE `key` = $x";

    mysqli_query($conn, $query2);

    echo "<font color='#FFFF00'>Placing text from <font color='#00FF00'>$result[adlink]</font> into database</font><br>"; 

    $x++;
    }

我错过/忘记了什么?

最佳答案

您缺少 $final_text 周围的单个队列,

$query2 = "UPDATE usedcars SET adtext = '".mysqli_escape_string($conn, $final_text)."' WHERE `key`= $x";

并始终通知您自己生产中的错误。通过像这样使用 mysqli_error()

mysqli_query($conn, $query2) or die(mysqli_error());

mysqli 不会自动保护您的查询使用 bindparam

关于php - 为什么我的 SQL 查询没有将数据放入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26814177/

相关文章:

Mysql:重复键更新触发不起作用

php - 将 bool 字段回显为是/否或其他值

php - 使用 URL 参数重定向网页

PHP : Convert dynamic uploaded image to specific color(dynamic color)

mysql - 选择 friend 的 friend mysql

php - 如何在 MySQL 列中使用二进制数据类型

带有附件问题的 php outlook 日历事件

Php 框架或模板引擎或其他东西?

php - Xcode 4.1 iOS 引用Joomla generated Database via PHP

MySQL 使用临时排序;使用文件排序