duanfeigui6655 2016-11-18 07:13
浏览 65
已采纳

如何以单一形式发布输入和选择类型

In posting.php file i wrote below code. In single form i included both Input type [textfield] & Select [options] type and when i submit form , i am getting error as Notice: Undefined index: designerorder_id

Form

<form  method="post">
<div id="ordernumbers">
          <select name ="designerorder_id">
            <option>Select Order</option>
          </select>
        </div>
<input type="text" name="paid_status" />

<input name="register1" type="submit"  onclick="return updatepayment(); "/>

Php

if (isset($_POST['register1'])) {

  $designerorder_id = trim($_POST['designerorder_id']);
  $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT);

  $stmt = $reg_user->runQuery("SELECT * FROM order_details");
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();


    if ($reg_user->register1($designerorder_id,  $paid_status)) {
      $id = $reg_user->lasdID();
      $key = base64_encode($id);
      $id = $key;

      $message = " updated database";

   //   $subject = "Confirm updation";

    //  $reg_user->send_mail($email, $message, $subject);
      $msg = "database updated ";

    } else {
      echo "sorry , Query could no execute...";
    }
  }

script

function getOrderDetail(e)
  {
    var designerId=e.target.options[e.target.selectedIndex].value;    
    var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?designer_id="+designerId+"&opration=2";
       var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
              document.getElementById('ordernumbers').innerHTML =result;

            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
     }

What i tried is ,

When i researched google, i found links like link1 link2 , link3 which using only Select [options] [not input type ] inside form. in some other links they are using JS to achieve this, also i tried as in link5 and tried below kinds of code :

$selected_val = $_POST['designerorder_id'];
$stud = explode("_",$_POST['designerorder_id']);

but nothing working for me. i almost spent 2 days before asking question, i am completely new to php, please help me.

Edit - complete code of posting.php file

<?php 

require_once 'dbconfig.php';
require_once 'class.user.php';
include 'home.php';
print_r($_POST);
//$reg_user = new USER();
$reg_user='';


$stmt = $user_home->runQuery("SELECT * FROM tbl_users");
  $stmt->execute(array(":uid" => $_SESSION['userSession']));
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();
?>

<?php

var_dump($_POST);

  if (isset($_POST['register1'])) {



  $designerorder_id = trim($_POST['designerorder_id']);
//  $selected_val = $_POST['designerorder_id'];
//$stud = explode("_",$_POST['designerorder_id']);
  $product_id = trim($_POST['product_id']);
  $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT);
  $due_date = trim($_POST['due_date']);

  $stmt = $reg_user->runQuery("SELECT * FROM order_details");
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $stmt->execute();


    if ($reg_user->register1($designerorder_id, $product_id, $paid_status, $due_date)) {
      $id = $reg_user->lasdID();
      $key = base64_encode($id);
      $id = $key;

      $message = " updated database";

   //   $subject = "Confirm updation";

    //  $reg_user->send_mail($email, $message, $subject);
      $msg = "database updated ";

    } else {
      echo "sorry , Query could no execute...";
    }
  }



?>

<style type="text/css">
  .paymentstatus{width:70%;margin: auto!important;}
  .inputpayment{/*width: 20%;clear:both;*/}
</style>


<div class="paymentstatus">
 <form class="form-signin" method="post"  action="posting.php" id="myFormId"> 
    <h2 class="form-signin-heading">Designer Payment Status</h2> 


    <table>


    <!-- Designer -->
      <tr>

        <td> Designer  </td>

        <td>
          <select onchange="getOrderDetail(event);" >
            <option>Select Designer</option>
            <?php while($data = $stmt->fetch())  { if($data['type']=="admin")continue;?>
              <option value="<?php echo $data['userID'];?>"><?php echo $data['name'];?></option>
            <?php } ?>
          </select> 
        </td> 

      </tr> 


     <!-- Designer Order Number: -->

    <tr>

        <td>Number: </td>

      <td>

        <div id="ordernumbers">
          <select name ="designerorder_id">
            <option>Select Order</option>
            <option value="1">abc</option>
          </select>
        </div>

      </td>

    </tr> 


      <!-- Product Related To Order Number:  -->

      <tr>  

        <td>Products</td>

        <td>

        <div id="productnumbers">
          <select name="product_id">
            <option>Select Products</option>
          </select>
          </div>

        </td>

      </tr>


      <!--  Paid Status: -->

      <tr>
        <td>Paid :</td>


        <td>
          <input type="text" class="inputpayment" placeholder="PaidStatus" name="paid_status" value="Paid" readonly="readonly" />
        </td>

      </tr>


      <!--  DueDate:-->

       <tr>
        <td>Due Date</td>


        <td>
          <input type="text" class="inputpayment" id="datepicker" placeholder="Duedate" name="due_date" value=""/>
        </td>
      </tr>



    </table>
    <hr/>


   <input class="btn btn-large btn-primary" name="register1" type="submit" id="btnSubmit" value="Update Payment" onclick="return updatepayment(); "/>

  </form>

</div>
<link rel="stylesheet" href="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/css/jquery-ui.css"> 

<script src="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/js/outthinking/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(

  /* This is the function that will get executed after the DOM is fully loaded */
  function () {
    $( "#datepicker" ).datepicker({
      changeMonth: true,//this option for allowing user to select month
      changeYear: true //this option for allowing user to select from year range
    });
  }

);
  function getOrderDetail(e)
  {
    var designerId=e.target.options[e.target.selectedIndex].value;  
//var designerId=e.target.options[e.target.options.selectedIndex].‌​value;  
    var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?designer_id="+designerId+"&opration=2";
       var request = jQuery.ajax( {
                url: url ,
                type: 'POST',                      
            } );

            request.done( function (result)
            {  
              document.getElementById('ordernumbers').innerHTML =result;

            } );
            request.fail( function ( error )
            {
                console.dir(error);             
            } );
     }
  function getProductDetail(e)
  {    
    var productId = $("#dproductselect option:selected").attr("class");  
    var finalstrig=productId.split(",");
    alert(finalstrig[1]);
    var select='';
    select+='<select><option>Select Product</option>';

    for(i=0;i<finalstrig.length;i++)
    {
      if(finalstrig[i]!=0)
      {
        select +='<option value="'+finalstrig[i]+'">'+finalstrig[i]+'</option>';
      }
    }
    select +='</select>';   
    document.getElementById('productnumbers').innerHTML =select;
  }

</script>

<script>

var request = jQuery.ajax( {
                url: 'posting.php' ,
                data : jQuery("#myFormId").serialize(),
                type: 'POST',                      
            } );


</script>

class.user.php

public function register1($designerorder_id, $product_id, $paid_status, $due_date)
  {
    try {

      $stmt = $this->conn->prepare("INSERT INTO order_details(designerorder_id, product_id, paid_status, due_date) 
            VALUES(:designerorder_id, :product_id, :paid_status, :due_date) ;");
      $stmt->execute(array(
          ":designerorder_id" => $designerorder_id,
          ":product_id" => $product_id,
          ":paid_status" => $paid_status,
          ":due_date" => $due_date

      ));
      return $stmt;
    } catch (PDOException $ex) {
      echo $ex->getMessage();
    }
  }
  • 写回答

3条回答 默认 最新

  • dongyimeng3764 2016-11-18 09:20
    关注

    first of all <select name= "designerorder_id"> remove space after name attribute , it should be <select name="designerorder_id">

    then give some id to the form like this.

    <form  method="post" id="myFormId">
    

    and in the ajax form pass the form data like this.

    var request = jQuery.ajax( {
                    url: url ,
                    data : jQuery("#myFormId").serialize(),
                    type: 'POST',                      
                } );
    

    and as i can see you are sending the data in the ajax with post method so why to use get variables in your url string ?

    pass your other needy varibales and its value using the <input type="hidden">

    it would be the simple way i guess.

    Also some changes are required in your function function getProductDetail(e) you have written

    select+='<select><option>Select Product</option>';
    

    change it to select+='<select name="product_id"><option>Select Product</option>';

    remove the var request = jQuery.ajax( { url: 'posting.php' , data : jQuery("#myFormId").serialize(), type: 'POST',
    } );
    , if your are refreshing the page you dont need this.

    in your php code change $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT); to $paid_status = $_POST['paid_status'];

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备