首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >将自定义PHP函数中的数据插入MySQL数据库

将自定义PHP函数中的数据插入MySQL数据库
EN

Stack Overflow用户
提问于 2011-08-01 07:17:52
回答 2查看 2.2K关注 0票数 0

在我的MySQL数据库中插入特定的代码行时遇到问题。它可以插入三行,但是由于某种原因,"html_href“行不能插入。下面是我的代码:

代码语言:javascript
代码运行次数:0
运行
复制
    function html_path() {
        $title = strtolower($_POST['title']);       // convert title to lower case
        $filename = str_replace(" ", "-", $title);  // replace spaces with dashes
        $html_href = $filename . ".html";               // add the extension
    }

和我的MySQL查询代码:

代码语言:javascript
代码运行次数:0
运行
复制
    $query = "INSERT INTO work (title, logline, html_href, synopsis) VALUES";
    $query .= "('".mysql_real_escape_string($_POST['title'])."',";
    $query .= "'".mysql_real_escape_string($_POST['logline'])."',";
    $query .= "'".html_path()."',";
    $query .= "'".mysql_real_escape_string($_POST['synopsis'])."')";

    $result = mysql_query($query);

标题、logline和概要的值可以很好地插入,但是html_href()函数会插入一个空行。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-08-01 07:20:08

看起来你的html_path()函数没有返回任何东西。

尝试:

代码语言:javascript
代码运行次数:0
运行
复制
function html_path() {
    $title = strtolower($_POST['title']);       // convert title to lower case
    $filename = str_replace(" ", "-", $title);  // replace spaces with dashes
    $html_href = $filename . ".html";               // add the extension
    return $html_href;
}
票数 0
EN

Stack Overflow用户

发布于 2011-08-01 07:21:29

您的html_path()不返回$html_href变量。添加

代码语言:javascript
代码运行次数:0
运行
复制
return $html_href;

在你关闭它之前,它应该能完美地工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6892968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档