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();
}
}
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 required variables 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 this code:
var request = jQuery.ajax( {
url: 'posting.php' ,
data : jQuery("#myFormId").serialize(),
type: 'POST',
} );
If you are refreshing the page you don't need this.
In your PHP code change $paid_status = password_hash($_POST['paid_status'], PASSWORD_DEFAULT);
to $paid_status = $_POST['paid_status'];
.