I have a question, is it possible to use the value stored in document.getElementById().value
, getElementsByName().value
, getElementsByClassName().value
as a parameter for SQL Query via PHP?
Example.
I have this line <input type="text" class="myinput" id="myinput" name="myinput" value="999-AAA-000">
Then I'll store the data in this element.
<script>
function myFunction() {
var foroutput = document.getElementsByClassName("myinput");
}
</script>
Is there a way for document.getElementsByClassName("myinput")
, or var foroutput
to be used as a parameter for SQL Query via PHP?
SCENARIO: The SQL Query is within the same page as the document.getElementsByClassName("myinput")
, will this work without using <form>
?
This is my code
<input type="text" class="decid" id="decid" name="decid">
// the data passed into this input box will be used as a parameter for SQL Query $id
<table id="example2" class="table table-bordered">
<thead>
<th>Schedule Date</th>
<th>Schedule Name</th>
<th>Recorded In</th>
<th>Recorded Out</th>
<th>Day Count</th>
<th>Day Value</th>
<th>N.D. Value</th>
<th>Leave Count</th>
<th>R.H. Count</th>
<th>R.H. Value</th>
</thead>
<tbody>
<?php
$id=$_POST['id'];
$sql = "SELECT fingerscanno, scheduledate, schedulename, recordin, recordout, noofdays, rate, nightdifferential, leaveday, regularholiday, specialholiday, referenceno
FROM payrollrecords WHERE fingerscanno='$user' and referenceno='$id'";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
echo "
<tr>
<td>".$row['scheduledate']."</td>
<td>".$row['schedulename']."</td>
<td>".$row['recordin']."</td>
<td>".$row['recordout']."</td>
<td>".$row['noofdays']."</td>
<td>".$row['rate']."</td>
<td>".$row['nightdifferential']."</td>
<td>".$row['leaveday']."</td>
<td>".$row['regularholiday']."</td>
<td>".$row['specialholiday']."</td>
</tr>
";
}
?>
</tbody>
</table>
A sample would be extremely great. Thank you.
EDIT:
Why won't this work?
<input type="text" class="decid" id="decid" name="decid">
<script type="text/javascript">
var abc = document.getElementById("decid").value;
<?php $abc = "<script>document.write(abc)</script>"?>
</script>
<?php echo $abc;?>