开发者

PHP: Having a problem with get_post

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:

PHP: Having a problem with get_post

After I enter a search term the pages looks the same BUT after going View -> Page Source I noticed something int开发者_如何学Pythoneresting. 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>


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]);
}


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

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


Surely you can change:

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

To:

$mySearchTerm = $_POST['searchTerm'];


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.


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜