2016-09-23 14 views
0

以下の文をどのように動作させるのですか?私はfunction.phpに値を投稿するフォームを持っています。場所に向かってではなく、.htmlファイルをfunction.phpにコンテンツとして含めることは可能ですか?私は難しい方法を学ぶ新しい学生です。PHPからの条件付き書式

<?php 
    if ($_POST['city'] = 'london'){ 
    header('Location: london.html'); 
    } 
    if ($_POST['city'] = 'manchester'){ 
    header('Location: manchester.html'); 
    } 
    if ($_POST['city'] = 'conventry'){ 
    header('Location: coventry.php'); 
    } 
    exit; 

?> 
+1

'($ _POST [「都市」] =「manchester''を比較の代わりに割り当て – Ghost

答えて

0

== if文ではなく、=を使用する必要があります。

<?php 
    if ($_POST['city'] == 'london'){ 
     header('Location: london.html'); 
    } 
    if ($_POST['city'] == 'manchester'){ 
     header('Location: manchester.html'); 
    } 
    if ($_POST['city'] == 'conventry'){ 
     header('Location: coventry.php'); 
    } 
    exit; 
?> 

、これを試してみては詳細は下記のリンクをチェックしてください。 https://www.tutorialspoint.com/php/php_decision_making.htm

0

あなただけ先のストレートスワップとしての場所に値を使用している場合 - あなたはまったくIFSを必要としない - ちょうど場所に変数を置く:

<?php 
    $city = $_POST['city']; 
    header('Location:' . $city . '.html'); 
    exit; 
?> 

//$city = london; 
//header('Location:london.html'); 

あなたの場合別のファイル拡張子を持っている - あなたがここに表示さなどの.htmlと.PHPを - あなたはif文を減らすためにswitch文を使用することができます。

<?php 
     $city = $_POST['city']; 

     switch ($city) { 
     case "london": 
      header('Location: london.html'); 
      break; 
     case "manchester": 
      header('Location: manchester.html'); 
      break; 
     case "coventry": 
      header('Location: coventry.php'); 
      break; 
     default: 
      echo "Your destination did not match any of our available cities"; 
     } 
    exit; 
    ?>