dtrt2368 2014-04-22 16:20
浏览 46

表单中的多个字段出错

I am creating a page where user enters the details through a registration form for a bank database. If the input values exits in the database then it is redirected to the next page. The problem associated with the code below is that when the user enters the details it redirects to the same registration page. The page is accessed through a separate file where the connection with the database is already established. No problem with the connection. I have created a file 'index.php' which invokes the registration page and the php code shown below. another file core.php is referred to the index.php which contains the session_start(). The code works well when i am limiting the form to only two fields i.e cust_name & card_no. Please reply. Thanks in advance. Here is my code:

    <?php
    //require 'core.php';
    //echo $current_file;

    if (isset($_POST['cust_name']) && isset($_POST['card_no']) && isset($_POST['cvv']) && ($_POST['exp_month']) && ($_POST['exp_year'])) //error possibly in this part  
    {

               $cust_name = $_POST['cust_name'];
               $card_no = $_POST['card_no'];
               $cvv = $_POST['cvv'];
               $exp_month = $_POST['exp_month'];
               $exp_year = $_POST['exp_year'];

       if(!empty($cust_name) && !empty($card_no) && !empty($cvv) && !empty($exp_month) && !empty($exp_year)) //error possible in this part
       {
              $query = "SELECT id FROM bank WHERE cust_name='$cust_name', card_no='$card_no',cvv='$cvv', exp_month='$exp_month',exp_year='$exp_year' ";
              if($query_run = mysql_query($query))
              {
                $query_num_rows = mysql_num_rows($query_run);
                 if($query_num_rows==0)
                 {
                   echo 'Invalid Card details';
                 }
                 else if($query_num_rows==1)
                 {
                   //echo 'OK!!';
                   $user_id = mysql_result($query_run,0,'id');
                   $_SESSION['user_id']=$user_id; //starts the session
                    header('Location:login2.php');/*redirects if the details are present in                  database*/        
                 }
              }      
        }   

        else
       {
           echo 'PLEASE ENTER DETAILS';
       } 
    }
    ?>


    <form action ="<?php echo $current_file; ?>" method="POST">//registration form

    Card Name:<input type = "text" name = "cust_name"><br/>

    Card No:<input type = "text" name = "card_no"><br/>

    CVV:<input type = "text" name = "cvv"><br/>

    Expiry Month & Year<select name="exp_month"><br/>
    <option selected value="janauary">January</option>
    <option value="february">February</option>
    <option value="march">March</option>
    <option value="april">April</option>
    <option value="may">May</option>
    <option value="june">June</option>
    <option value="july">July</option>
    <option value="august">August</option>
    <option value="september">September</option> 
    <option value="october">October</option>
    <option value="november">November</option>
    <option value="december">December</option>
    </select>
    <select name="exp_year"><br/>
    <option selected value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    <option value="2021">2021</option>
    <option value="2022">2022</option>
    <option value="2023">2023</option>
    <option value="2024">2024</option>
    <option value="2025">2025</option><br/>
    </select><br/>


    <input type="submit" value="submit">
    <input type="reset" value="reset"><br/> 

    </form>

<----index.php---->
<?php
require 'database.php'; //establishes database connection
require 'core.php'; //uses core.php
include 'login_form.php';//redirects to login_form
?>

<----core.php-----?
<?php
ob_start();
session_start(); // starts the session
$current_file = $_SERVER['SCRIPT_NAME'];//used at login_form
?>
    --------------------------------------
  • 写回答

2条回答 默认 最新

  • 普通网友 2014-04-22 16:44
    关注

    The reason your IF statement works with two fields is because you can only have one && expressions in an IF statement in PHP. You're going to have to separate your && statements. Though, it would be better and safer if you just check each POST individually:

    if ( isset($_POST['name'] ){}

    Then run what you want it to do.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序