Jump to content

Passing values inside and outside the page


chrishutagalung

Recommended Posts

So I have this problem with AJAX. I want to pass the value from the selected dropdown with ajax so that when user selected one of the value in dropdown list(from Oracle DB) it pulls the corresponding value and send it inside the page for processing.

 

So the database schema is like this,

 

HEAD_MARK              QTY    CUTTING   ASSEMBLY    WELDING   DRILLING  FINSHING
--------------- ---------- ---------- ---------- ---------- ---------- --------- 
TEST-2                 222          0          0          0          0         0
 
INI TEST               999          0          0          0          0         0
 
TEST_RUN1               11          2          2          2          2         2

 

 

and my Demo.php is like this. It pulls the Head_mark value from the database and direcly passing the value to process the,

1. Show the corresponding quantity

2. Use the quantity to compare the cutting. Lets say cutting value in the db today is 2 and the quantity is 10. So in the input tag, min="2" and max="10". And user can input new value and update it to the database according to the selected input

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
        function OnSelectionChange (select) {
            var selectedOption = select.options[select.selectedIndex];
            //some ajax checkpoint for checking value
            //alert ("The selected option is " + selectedOption.value);          
                        jQuery.ajax({
                                url: location.href,
                                data: {'hm':selectedOption.value, 'ajax':1},
                                type: "POST",
                                success: function( data ) {
                                        jQuery("#lbl_qty").html(data);//PRINT QTY TO THE SCREEN
                                }                           
                        });
                        //some ajax checkpoint
                        //alert('after ajax');
        }
        
$(function(){
//insert record
$('#insert').click(function(){
var jcutting = $('#fcutting').val();
var jassembly = $('#fassembly').val();
                        var jwelding = $('#fwelding').val();
                        var jdrilling = $('#fdrilling').val();
                        var jfinishing = $('#ffinishing').val();

//syntax - $.post('filename', {data}, function(response){});
$.post('../update_bar/data.php',
                                    {action: "insert", 
                                     cutting:jcutting, assembly:jassembly, welding:jwelding, 
                                     drilling:jdrilling, finishing:jfinishing},
                              function(res){
                                    $('#result').html(res);
});});

//show records
$('#show').click(function(){
$.post('data.php',{action: "show"},function(res){
$('#result').html(res);
});
});
});
</script>
</head>
<body>
    
    <?php
         // DROPDOWN VALUES TO PULL COMPONENT FROM THE DB
         $result = oci_parse($conn, 'SELECT HEAD_MARK FROM FABRICATION');
         oci_execute($result);
                             
         echo '<SELECT name="headmark" id="headmark" onchange="OnSelectionChange(this.value)">'.'<br>';
         echo '<OPTION VALUE=" ">'."".'</OPTION>';

         while($row = oci_fetch_array($result,OCI_ASSOC)){
         $HM = $row ['HEAD_MARK'];
         echo "<OPTION VALUE='$HM'>$HM</OPTION>";
         }
         echo '</SELECT>';
     ?>

<?php 
        // IT DIRECTLY SHOWS THE QUANTITY FOR THE GIVEN HEADMARK WHEN USER SELECT ONE OF THE HEADMARK FROM THE DROPDOWN
        // BUT IT SHOWS Notice: Undefined index: hm in C:\xampp\htdocs\WeltesInformationCenter\update_bar\demo.php on line 95
        $qty_query_result = oci_parse($conn, "SELECT QTY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'");
        oci_execute($qty_query_result);
       
        oci_bind_by_name($qty_query_result, 'QTY', $quantity);
        
        echo 'QUANTITY :'.$quantity;
     ?>

<!-- MAX PLACEHOLDER SHOULD BE GATHERED FROM THE QUANTITY FROM THE CORRESPONDING COMPONENT--> Cutting: <input type="number" min="0" id="fcutting" /> Assembly: <input type="number" min="0" id="fassembly" /> Welding: <input type="number" min="0" id="fwelding" /> Drilling: <input type="number" min="0" id="fdrilling" /> Finishing: <input type="number" min="0" id="ffinishing" /> <button id="insert">Insert</button> <h2>Show Records</h2> <button id="show">Show</button> <p>Result:</p> <div id="result"></div> </body> </html>

 

And the Data.php looks like this

<?php
	//if insert key is pressed then do insertion
	if($_POST['action'] == 'insert'){

		$cutting  = $_POST['cutting'];
		$assembly = $_POST['assembly'];
                $welding  = $_POST['welding'];
		$drilling = $_POST['drilling'];
                $finishing = $_POST['finishing'];

		$sql   = "UPDATE FABRICATION SET CUTTING = '$cutting', ASSEMBLY = '$assembly', WELDING = '$welding',
                        DRILLING = '$drilling', FINISHING = '$finishing' WHERE HEAD_MARK = '{$_POST["hm"]}''";
		$query = oci_parse($conn, $sql);
                $query_exec = oci_execute($query);
		if($query_exec){
                    oci_commit($query_exec);
			echo "Record Inserted.";
		}else {
			echo "Something Wrong!";
		}
	}
	//if show key is pressed then show records
	if($_POST['action'] == 'show'){
		$sql   = "select * from FABRICATION WHERE HEAD_MARK = 'TEST_RUN1'";
		$query = oci_parse($conn, $sql);
                $query_exec = oci_execute($query);

		echo "<table border='1'>";
		while($row = oci_fetch_assoc($query)){
			echo "<tr><td>$row[HEAD_MARK]</td><td>$row[CUTTING]</td><td>$row[ASSEMBLY]</td><td>$row[WELDING]
                            </td><td>$row[DRILLING]</td><td>$row[FINISHING]</td></tr>";
		}
		echo "</table>";
	}
?>

So basically I dont know how to pass the head_mark value to the function in Data.php.

 

The error is like this,

 

Notice: Undefined index: hm in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 35

Warning: oci_parse(): ORA-01756: quoted string not properly terminated in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 36

Warning: oci_execute() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\WeltesInformationCenter\update_bar\data.php on line 37

Something Wrong!

 

PLease any kind of help would be appreciated

Edited by chrishutagalung
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.