PHP: Having a problem with get_post

自闭症网瘾萝莉.ら 提交于 2020-01-22 02:49:12

问题


I am having a problem with the get_post method. Here is my code:

<!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>

The code works well before a search term is entered. The html looks as expected and this page is displayed in a browser:

After I enter a search term the pages looks the same BUT after going View -> Page Source I noticed something interesting. The end of the page looks like this:

Search <input type="text" name="searchTerm"/>
       <input type="submit" value="Add Record"/>
</pre>
</form>

NOTE: There is no ending </body></html>


回答1:


Turns out that get_post is not a PHP method. My textbook defined it on the next page as:

function get_post($var){
  return mysql_real_escape_string($_POST[$var]);
}



回答2:


I agree with sixtyfootersdude. The only thing missing is the database connection.

function get_post($conn, $var){
     return $conn->real_escape_string($_POST[$var]);
}



回答3:


Surely you can change:

$mySearchTerm = get_post('searchTerm'); # <- PROBLEM LINE!

To:

$mySearchTerm = $_POST['searchTerm'];



回答4:


There is no get_post() function in PHP perhaps you are calling an undefined function.

Add the following at the top of your PHP block

ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);

to see what it is going on.




回答5:


You MISSED include or require for your get_post function and parser will push error with disabled error reporting.

And at the top of script add:

error_reporting(E_ALL);
require_once('this_file_where_you_have_get_post.php');


来源:https://stackoverflow.com/questions/4068855/php-having-a-problem-with-get-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!