chrishutagalung Posted April 14, 2014 Share Posted April 14, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287761-sending-php-variable-with-jquery-to-another-page/ Share on other sites More sharing options...
Ch0cu3r Posted April 14, 2014 Share Posted April 14, 2014 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); }); } Quote Link to comment https://forums.phpfreaks.com/topic/287761-sending-php-variable-with-jquery-to-another-page/#findComment-1476100 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.