doupa1883 2015-05-24 10:44
浏览 22
已采纳

php中的表单验证问题?

I have a form with several fields and with 4 radio buttons. Based on this radio button click, the form has to be validated. All the fields in the form need not be validated.

Check this link, the similar thing I want:

https://stackoverflow.com/questions/30396119/i-have-issue-in-php-validation-for-nested-if-else-condition

The code i tried:

<?php
        $guestname="";$validguestname="";
    $guestno= "";$validguestno="";
    $nochild= 0;$validnochild="";
    $noadults=0;$validnoadults="";
    $infants =0;$validinfants="";
    $noofperson ="";$validnoofperson="";
    $check_in="";$validdate1="";
    $check_out="";$validdate2="";
    $noofnight = "";$validnoofnight="";
    $room_type="";$validroom_type="";
    $nfroom="";;$validnfroom="";
    $noofextrabed ="";$validnoofextrabed="";
    $roomarray="";$validroomarray="";
    $mealplan="";$validmealplan="";
    $rateperday ="";$validrateperday="";
    $rateperbed ="";$validrateperbed="";
    $total_amount ="";$validtotal_amount="";
    $advance   = "";$validadvance="";
    $balance   ="";$validbalance="";
    $receiptno ="";$validreceiptno="";
    $dateofremitance ="";$validdateofremitance="";
    $bankorcash="";$validbankorcash="";
    $bank_name="";$validbank_name="";
    $bookedby="";$validbookedby="";
    $paymentmode  ="";$validpaymentmode="";
    $bookingtype="";$validbookingtype="";
    $reservationstatus="";$validreservationstatus="";
    $book_by="" ;$validbook_by="";
    $agentname= "";$validagentname="";
    $agentphoneno="";$validagentphoneno="";
    $error_message="";$error_message1="";$error_message2="";
    $date3=date('Y-m-d');
   if(isset( $_POST['submit']))
   {            
    $guestname= $_POST['guest_name'];
    $bookingtype=$_POST['booking_type'];echo $bookingtype."helooo";
    $guestno= $_POST['guest_no'];
    $reservationstatus=$_POST['reservation_status'];
    $nochild= $_POST['no_child'];
    $book_by= $_POST['bookby'];
    $agentname= $_POST['bookbyother'];
    $agentphoneno= $_POST['phone1'];
    $noadults= $_POST['no_adults'];
    $infants = $_POST['no_infants'];
    $noofperson = $nochild+$noadults+$infants;
    $check_in=trim( $_POST['checkin']);
    $check_out=trim( $_POST['checkout']);
    $noofnight = $_POST['no_of_days'];
    $room_type= $_POST['roomtype'];
    $nfroom= $_POST['noofroom'];    
    $noofextrabed = $_POST['no_of_extra_bed'];
    $roomarray= $_POST["room_no"];
    $mealplan= $_POST['meal_plan'];
    $rateperday = $_POST['rp_day']; 
    $rateperbed   = $_POST['extrarate'];
    $total_amount =  $_POST['totalamount'];
    $advance   = $_POST['advance_amount'];
    $balance   = $_POST['val_username'];
    $receiptno = $_POST['receipt_no'];
    $dateofremitance = $_POST['date_remitance'];
    $bankorcash= $_POST['paymentmode'];
    $bank_name= $_POST['bankname'];
    $booking_date=date('y-m-d');
    $bookedby= $_POST['adminbooking'];
    $paymentmode  = $_POST['payment_mode'];
    $date1 = date('Y-m-d', strtotime($check_in));
    $date2 = date('Y-m-d', strtotime($check_out));
///1st condition///
    if($bookingtype=="direct" && $reservationstatus=="H" && other_conditions)
    {

        insert query;

    }
    ///2nd condition///
    else if($bookingtype=="direct" && $reservationstatus=="C" && othercondition for particular fields)
    {insert query;}
    ///3rd condition///
    else if($bookingtype=="agent" && $reservationstatus=="H" && $book_by=="other")
    {echo "agent anfd holding and other";}
    ///4th condition///
    else if($bookingtype=="agent" && $reservationstatus=="H" && $book_by!="other")
    {echo "agent anfd holding and not toher";}
    ///5th condition///
    else if($bookingtype=="agent" && $reservationstatus=="C" && $book_by=="other")
    {echo "agent anfd confirm and other";}
    ///6th condition///
    else if($bookingtype=="agent" && $reservationstatus=="C" && $book_by!="other")
    {echo "agent anfd confirm and not other";}
    //else condiition
    else
    {echo "choose ur option";}
  • 写回答

1条回答 默认 最新

  • dongnang8192 2015-05-24 15:58
    关注

    From what I gather, your problem seems to be figuring out the full range of values that have been entered on the first. You can try one of two approaches.

    1. Get your form values default options if they have not been entered by the user. As an example:
    if (!empty($_POST['')) {
        $reservationstatus=$_POST['reservation_status'];
    }
    else {  
        $reservationstatus=false; 
    }
    

    then your following query will work:

    if($bookingtype=="direct" && $reservationstatus=="H" && other_conditions)
    {
        your_query_here();
    }
    
    1. Check explicitly for entered values, but this makes for a more complex check.
    if( ((!empty($_POST['booking_type']) && 
        ($_POST['booking_type']=="direct") )  && 
        ((!empty($_POST['reservation_status']) && 
        ($_POST['reservation_status']=="H") )  && 
        other_conditions)
    {
        your_query_here();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题