如何在php/Html编程语言中使用if-else语句
我是PhP新手。我试图使用if/else语句来请求(包括'user_index_Big_Data.php'),并使用不同的输入 当我运行代码时,它将输出所有的.php表单。但我只希望它只输出一个表单如何在php/Html编程语言中使用if-else语句,php,Php,我是PhP新手。我试图使用if/else语句来请求(包括'user_index_Big_Data.php'),并使用不同的输入 当我运行代码时,它将输出所有的.php表单。但我只希望它只输出一个表单 <html> <head> <LINK href="style.css" rel="stylesheet" type="text/css"> <title>Login</title> </head> <bo
<html>
<head>
<LINK href="style.css" rel="stylesheet" type="text/css">
<title>Login</title>
</head>
<body>
<form action="" method="post">
<h1>Enter Key word to search</h1>
<p>Search <input type="text" name="username" placeholder='e.g. big data, Big Data'></p>
<p><input type="submit" name="submit" value="Search"></p>
</form>
</body>
</html>
<?php
$user = ("Big Data" || "big data" or "Big data" or "BIG DATA" or "big data analytics" or "BIG DATA ANALYTICS"
or "big data analysis");
$user1 = ("machine learning" || "MACHINE LEARNING" or "Machine Learning" or "Machine learning");
$user2 = ("Data center" || "Efficient Energy" or "Renewal Energy" or "Multi-Agents");
//$pass = "itsme";
if(isset($_POST["submit"])) {
if($_POST["username"] == $user )
include 'user_index_Big_Data.php';}
if(isset($_POST["submit"])) {
if($_POST["username"] == $user1 )
include 'user_index_machine_Learning.php';
}
if(isset($_POST["submit"])) {
if($_POST["username"] == $user3 )
include 'Energy.php';
}
else {
echo "Incorrect Key Word";
}
?>
登录
输入要搜索的关键字
搜寻
我希望代码只输出一个表单。但它输出所有形式。它会回显表单的所有结果。如果将各种关键字添加到数组中,则可以使用_array中的
测试匹配情况。
~尽管不需要包含所有可能的大写/小写变体,只需将提供的用户数据转换为小写等
<html>
<head>
<link href='style.css' rel='stylesheet' />
<title>Login</title>
</head>
<body>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['type'] ) ){
/* Process secondary form submission - do whatever needs to be done with secondary forms */
ob_clean();
$_POST['time']=time();
exit( json_encode( $_POST ) );
}
if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['submit'], $_POST['username'] ) ){
/* Process primary form to select secondary form */
$file=false;
$user=array('big data','big data analytics');
$user1=array('machine learning');
$user2=array('data center','efficient energy','renewal energy','multi-agents');
$username=trim( strtolower( urldecode( $_POST['username'] ) ) );
if( in_array( $username, $user ) )$file='user_index_Big_Data.php';
if( in_array( $username, $user1 ) )$file='user_index_machine_Learning.php';
if( in_array( $username, $user2 ) )$file='Energy.php';
if( $file ){
if( file_exists( $file ) )require $file;
else printf( 'Unable to find file: "%s" to suit username "%s"', $file, $_POST['username'] );
} else {
printf( 'Incorrect Key Word: "%s"', $_POST['username'] );
}
}
?>
<form method='post'>
<h1>Enter Key word to search</h1>
<p>Search <input type='text' name='username' placeholder='e.g. big data, Big Data'></p>
<p><input type='submit' name='submit' value='Search'></p>
</form>
</body>
</html>
登录
$user=(“大数据”|“大数据”或…
-这只会导致$user
具有布尔值true
。无法进行比较(?)这样,这是完全错误的。如果您想检查POST参数是否是多个可能值中的一个,请将这些值放入一个数组,并使用数组中的进行检查。非常感谢您。我非常高兴进行此更正。谢谢。
<?php
/* Big Data : user_index_Big_Data.php */
?>
<form name='big-data' method='post'>
<input type='text' name='type' value='big data' />
<input type='submit' />
</form>
<?php
/* machine learning : user_index_machine_Learning.php */
?>
<form name='machine-learning' method='post'>
<input type='text' name='type' value='machine learning' />
<input type='submit' />
</form>
<?php
/* Energy : energy.php */
?>
<form name='energy' method='post'>
<input type='text' name='type' value='Energy' />
<input type='submit' />
</form>