【发布时间】:2017-04-01 23:12:44
【问题描述】:
在 posting.php 文件中我写了下面的代码。在单一表单中,我同时包含输入类型 [文本字段] 和选择 [选项] 类型,当我提交表单时,我收到错误 Notice: Undefined index: designerorder_id
表格
<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...";
}
}
脚本
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);
} );
}
我尝试的是,
当我研究谷歌时,我发现像 link1 link2 , link3 这样的链接只使用了Select [options] [不是输入类型] 在表单内。在其他一些links 他们正在使用 JS 来实现这一点,我也尝试过link5 并尝试了以下代码:
$selected_val = $_POST['designerorder_id'];
$stud = explode("_",$_POST['designerorder_id']);
但没有什么对我有用。我几乎花了 2 天的时间才提出问题,我对 php 完全陌生,请帮助我。
编辑 - posting.php文件
的完整代码<?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();
}
}
【问题讨论】:
-
使用
isset()方法检查designerorder_id是否设置 -
@Karthi 当我尝试代码时:
if (isset($_POST["designerorder_id"]) && !empty($_POST["designerorder_id"])) { echo "Yes, mail is set"; }else{ echo "N0, mail is not set"; },我得到了这个结果N0, mail is not setarray(0) { } -
是的,这就是问题所在。
-
@Karthi 请告诉我如何设置
designerorder_id,我在整个谷歌中研究过,都提到如果只有selected options,他们没有提到如果两者都有@ 987654340@...... -
@Karthi 以单一形式,我包括两种类型的值 - 一种是
input type' :`,另一种是<select name ="designerorder_id">,用户将在输入字段中输入值并选择值,所以我想将这两个值都保存在数据库中......但是当我提交表单时,我收到错误:Notice: Undefined index: designerorder_id
标签: javascript php html forms