初学者:IF语句/ PHP / HTML问题

时间:2014-03-19 21:23:06

标签: php html

我提前为我缺乏PHP和HTML知识而道歉。我已经在互联网上搜索了3/4天,试图创建一个可能是一个简单的系统。我需要用户在下一页加载之前输入一个数字。我的页面上有一个IF语句。 1.PHP

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
<div id="container">
<div id="authorise">
<form action="2.php" method="post">
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br>
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
</div>
</div> 

2.PHP

<?php
  if ($_POST['digits'] === '210392') 
  {echo 'https://www.facebook.com/'
 ?>

但我首先需要一个表单,用户可以输入代码&#39; 210392&#39;并按提交。然后可以发生if语句。我知道如何做一个表单,但不知道如何为该表单指定一个变量名称&#39;数字&#39;。感谢所有帮助。

5 个答案:

答案 0 :(得分:4)

基本形式:

<form action="your_file.php" method="post">
  <input type="text" name="digits" />
  <input type="submit" name="submit" />
</form>

然后在your_file.php

<?php
  if ($_POST['digits'] === '210392') {
  // etc.

$_POST是一个超全局数组,它将所有数据都发布到您的脚本中。在这种情况下,digits是该数组中的索引。它来自输入字段的名称。

答案 1 :(得分:0)

首先需要创建一个具有非常重要的name属性的输入,稍后您将使用该属性。

<form method="post">
    <input type="password" name="mypassword" />
    <button type="submit">Go</button>
</form>

PHP:

//Post method access with $_POST variable:
if ($_POST['mypassword'] == 'my-password') { //Oh, you should probably use SSH and hash the password
    //Hooray!
}

答案 2 :(得分:0)

    <form action="https://scm-intranet.tees.ac.uk/users/l1071039/bobbin/admin.php" method="post">
      Password : <input type="password" name="pwd" />
      <input type="submit" name="send">
    </form>

    // admin.php
    <?php 
    if( isset($_POST['pwd']) ){
        $pwd = $_POST['pwd'];
    }
    ?>

答案 3 :(得分:0)

使用标题。而不是回声。

   <?php
   if ($_POST['digits'] === '210392') 
   {
   header (loaction:https://www.facebook.com/);
   }
   ?>

答案 4 :(得分:0)

<form action="check.php" method="POST">
<input type="text" name="digits" />
<input type="submit" value="click here" />
</form>

//in check.php 

if (isset($_POST['digits']) and $_POST['digits'] == 12345){
header("Location: http://google.com");
} 
else {
echo " error !!";
}

从w3school学习HTML http://www.w3schools.com/html/html_forms.asp

和php http://www.w3schools.com/PhP/php_forms.asp