I'm trying to figure out how to get a SQL DB write into my file that is largely javaScript and JQuery. I've found some php info online, but I'm having trouble getting the php into my code with everything else that's there. I'm trying to utilize an array where I put user entered info from an html table, and call a method that uses the array as a parameter. I have made my entire file a php file, but I'm having trouble figuring out where to put the php <?php ?> delimeters without having my bigTableRows array go out of scope, or other run-time error messages. After I figure this out I need to do a MS SQL write. Right now, I see this error message, but no table. Line 83 is the line after the <?php, where I have echo(bigTableRows[0];
Parse error: syntax error, unexpected '[' in E:\visE\jqproject\web\BigTable.php on line 83
If I take away the [0] part, I get a syntaxError, but see the table ok:
missing; before statement.
This is what it looks like:
BigTable.php:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/>
<title>Big Table</title>
<script type="text/javascript" src="js/jquery-1.11.0.js"></script>
<script type="text/javascript">
//Used to make row editable or not
$(document).ready(function () {
$('.editbtn').click(function () {
var currentTD = $(this).parents('tr').find('td');
if ($(this).html() === 'Edit') {
$.each(currentTD, function () {
$(this).prop('contenteditable', true);
});
} else {
$.each(currentTD, function () {
$(this).prop('contenteditable', false);
});
}
//change button text when hit it between edit/save
$(this).html($(this).html() === 'Edit' ? 'Save' : 'Edit');
var bigTableRows = getBigTableRowData(0); //first row
console.log("bigTableRows other", bigTableRows);
InsertData(bigTableRows);
});
function InsertData($theDataArr)
{
//The php part below isn't working**********************
$bandY = $theDataArr[0];//$_POST['bandY'];
$bandM = $theDataArr[1];//$_POST['bandM'];
$bandC = $theDataArr[2];//$_POST['bandC'];
$bandK = $theDataArr[3];//$_POST['bandK'];
$comment = $theDataArr[4];//$_REQUEST['comment'];
console.log("bandY php: ", $bandY);
console.log("bandM php: ", $bandM);
console.log("bandC php: ", $bandC);
console.log("bandK php: ", $bandK);
console.log("comment php: ", $comment);
<?php //where to put this and still have variable info******
echo(bigTableRows[0]);
//console.log("bandY php: ", $bandY);
//console.log("bandM php: ", $bandM);
//console.log("bandC php: ", $bandC);
//SQL dB write to follow after I can access data**************
?>
}
});
</script>
<script>
function getBigTableRowData(rowNum)
{
//I just need row data for the one that was just edited/saved******
var rowText = $("#bigTable tbody tr:eq(" + rowNum + ") td").map(function() {
// Find all of the table cells on this row.
// Determine the cell's row text
return $(this).text();
}).get();
return rowText;
}
</script>
</head>
<body>
<div class="form">
<p>
<h1> Visual Evaluation Entry Table </h1>
</p>
</div>
<table id="bigTable" border="1">
<thead>
<tr>
<th id="edit" class="col3">Edit/Save</th><th id="bandY" class="col3">Bands @263mm Y</th><th id="bandM" class="col3">Bands @263mm M</th><th id="bandC" class="col3">Bands @263mm C</th><th id="bandK" class="col3">Bands @263mm K</th><th id="Comments" class="col3">Comments</th></tr>
</thead>
<tbody>
<tr>
<td><button class="editbtn">Edit</button></td>
<td name="bandY" contenteditable="false"></td> <!-- //Row 0 Column 1-->
<td name="bandM" contenteditable="false"></td> <!--//Row 0 Column 2-->
<td name="bandC" contenteditable="false"></td> <!--//Row 0 Column 3-->
<td name="bandK" contenteditable="false"></td> <!--//Row 0 Column 4-->
<td name="comment" contenteditable="false"></td> <!--//Row 0 Column 4-->
</tr>
</tbody>
</table>
</body>
</html>
Some examples I've found are: php sql write, and put html table data into array
I know that if I take away the <?php delimeters, it would run ok (minus echo) (and access the array data), but I need them to do the php part. If I'm off-base on any of this, which I'm sure something is, feel free to let me know. I have a little php experience with xml/html, but I'm learning javaScript and JQuery, and I've never tried to put it all together before.