[英]Insert data from custom PHP function into MySQL database
I'm having problems inserting a particular line of code into my MySQL database. 我在将特定代码行插入MySQL数据库时遇到问题。 It inserts three rows just fine, but the "html_href" row isn't going in for whatever reason. 它可以插入三行,但出于任何原因“ html_href”行都不会插入。 Here is my code: 这是我的代码:
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
}
And my MySQL query code: 而我的MySQL查询代码:
$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);
The title, logline, and synopsis values go in just fine, but the html_href()
function inserts a blank row. 标题,日志行和提要的值都很好,但是html_href()
函数插入了空白行。
It looks like your html_path()
function isn't returning anything. 看来您的html_path()
函数未返回任何内容。
Try: 尝试:
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;
}
Your html_path() does not return the $html_href variable. 您的html_path()不返回$ html_href变量。 Add 加
return $html_href;
before you close it, and it should work perfectly. 在关闭它之前,它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.