Jump to content

Sending PHP Variable with jquery to another page


chrishutagalung

Recommended Posts

Hi folks,

 

I have this coding problem that I want to pass the PHP variable $row[HEADMARK] and $row[iD] to another page to process update to the oracle DB as user check the checkbox.

 

So on the data.php I have,

<html>
    <head>
        $('.cuttingCheckbox').change(function() {
             if (this.checked) {
               $.post('process_data.php', 
               { headmark : $($row[HEADMARK]).val(), 
                 headmark_id : $($row[ID]).val()},
                 function(response){ 
                 this.setAttribute("disabled", true), alert(headmark,headmark_id); }); 
               } 
           });     
        </script>       
    </head>

    <?php                
        
	// IF SHOW KEY HAS BEEN PRESSED
	if($_POST['action'] == 'show')
        {            
		$sql   = "SELECT * FROM SUB_MASTER_DRAWING
                          WHERE SUB_MASTER_DRAWING.HEAD_MARK = '{$_POST["hm"]}'";
                          
		$query = oci_parse($conn, $sql);
                $query_exec = oci_execute($query);
                
               
		while($row = oci_fetch_assoc($query)){
                      echo "<table border='1'>";
                            echo '<table cellspacing = "0"';
                                echo '<thead>';
                                echo '<tr><th>Head Mark</th>
                                          <th>Cutting</th>
                                          </tr></thead>';
                                
                                echo "<tbody>";
                                echo "<tr><td><b>$row[HEAD_MARK]/$row[ID]</b></td>";
                                            
                                          if ($row['CUTTING'] == 'Y'){                                   
                                              echo "<td><input type='checkbox' id='cuttingCheckbox'  name='cuttingCheckbox' checked='checked' disabled='disabled'/></td>";
                                          } else {
                                              echo "<td><input type='checkbox' class='cuttingCheckbox'  name='cuttingCheckbox' data-labelauty='Cutting done|Cutting NOT done'/></td>";
                                          }   
                     
                                          echo "</tr>";   
                                          echo "</tbody>";
                                echo "<table cellspacing = '0'";
                }
        echo "</table>";
     }//===> END OF 'SHOW'
?>
</html>

And on the process_data.php should update the variables to the database

<?php

$cuttingUpdateParse = oci_parse($conn,"UPDATE SUB_MASTER_DRAWING SET CUTTING = 'Y' WHERE HEADMARK = '$_POST[headmark]' AND ID = '$_POST[ID]]'");
$cuttingUpdateRes = oci_execute($cuttingUpdateParse);

if ($cuttingUpdateRes){
    echo "<script>alert('CUTTING UPDATED');</script>";
} else {
    echo "<script>alert('ERROR OCCURED');</script>";
}

?>

Somehow I couldnot get this code to work. even the alert on the jquery.

please help me guys

Million thanks

Link to comment
Share on other sites

ok... this is wrong

 

 

{ headmark : $($row[HEADMARK]).val(),
headmark_id : $($row[iD]).val()},

PHP variables cannot be read by javascript.

 

What you need to do is add two hidden input fields to your form, which hold the values of those variables, eg

echo "<tr><td><b>$row[HEAD_MARK]/$row[ID]</b>
        <input type=\"hidden\" name=\"HEAD_MARK\" value=\"$row[HEAD_MARK]\" />
        <input type=\"hidden\" name=\"ID\" value=\"$row[ID]\" />
</td>";

Then in your javascript you $.serialize the form fields and pass that as the data

$.post('process_data.php', $(form identifier).serialize(),
                 function(response){ 
                 this.setAttribute("disabled", true), alert(response); }); 
               }
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.