Reputation: 13
how to take the value from another .php file help me fix this:
<html>
<head>
</head>
<body>
<form name='answer' action="file2.php" method="post">
<input type="text" name="what">
<input type="submit" value="Login">
</form>
<div><?php echo $answer; ?></div>
</body>
</html>
And the code of file2.php file is as below:
<?php
if ($_POST['what']==animal){
$answer="dog";
}else{
$answer= "not animal";
}
I would like to know how can I get the value of the variable $answer with button, then what should I put at the line :
Upvotes: 1
Views: 5555
Reputation: 28564
Use require_once()
to include file2.php in your php file, then in your file you can access the variables in file2.php.
require_once("path of file2.php");
echo $answer;
Upvotes: 1