[英]PHP: Having a problem with get_post
我在使用get_post方法时遇到问题。 这是我的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload2</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1> Welcome to my search Engine </h1>
<?php
# SETUP
$thisFile = 'v4.php';
# INPUT FIELDS
echo <<< END
<form action="$thisFile" method="post">
<pre>
Search <input type="text" name="searchTerm"/>
<input type="submit" value="Add Record"/>
</pre>
</form>
END;
# EXTRACT INPUTTED FIELDSA
if(isset($_POST['searchTerm'])) {
# INITIALIZE INPUTTED VARIABLES
$mySearchTerm = get_post('searchTerm'); # <- PROBLEM LINE!
echo "You searched for: $mySearchTerm";
}
?>
</body>
</html>
该代码在输入搜索词之前效果很好。 html看起来像预期的那样,并且此页面在浏览器中显示:
输入搜索词后,进入“查看”->“页面源”后,页面看起来是相同的,但是我发现了一些有趣的东西。 页面的结尾如下所示:
Search <input type="text" name="searchTerm"/>
<input type="submit" value="Add Record"/>
</pre>
</form>
注意:没有结尾</body></html>
事实证明,get_post不是PHP方法。 我的课本在下一页将其定义为:
function get_post($var){
return mysql_real_escape_string($_POST[$var]);
}
我同意sixtyfootersdude。 唯一缺少的是数据库连接。
function get_post($conn, $var){
return $conn->real_escape_string($_POST[$var]);
}
您的get_post
函数缺少或include
require
,解析器将使用已禁用的错误报告来推送错误。
并在脚本顶部添加:
error_reporting(E_ALL);
require_once('this_file_where_you_have_get_post.php');
您当然可以更改:
$mySearchTerm = get_post('searchTerm'); # <- PROBLEM LINE!
至:
$mySearchTerm = $_POST['searchTerm'];
PHP中没有get_post()函数,也许您正在调用未定义的函数。
在PHP块的顶部添加以下内容
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
看看发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.