Hi All,
I have the following javascript code to dynamically create a table and populate it with data. Each time the user presses the "Add Row" button on my form, the addrow function is called and a row containing their data is added to the table. Here is the code:
This is working fine on my form but I am having trouble with the php processing script. I am having trouble with $query2. Please ignore the commented areas. They are for future headaches lol. Here is my processing script:
I am getting the following error:
The strange thing is that line #70 is in one of the commented areas. How can this be? Can anyone please help me figure out what I am missing here?
Thanks,
Ken
I have the following javascript code to dynamically create a table and populate it with data. Each time the user presses the "Add Row" button on my form, the addrow function is called and a row containing their data is added to the table. Here is the code:
JavaScript:
<SCRIPT language="javascript">
function addRow(tableID) {
if (!document.getElementById(tableID)) {
var body = document.getElementsByTagName("fieldset")[2];
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
tbl.appendChild(tblBody);
body.appendChild(tbl);
tbl.setAttribute("id", "dataTable");
tbl.setAttribute("border", "0");
}
var StartTime = document.getElementById('txtStartTime');
var EndTime = document.getElementById('txtEndTime');
var MaterialID = document.getElementById('txtMaterialID');
var Title = document.getElementById('txtTitle');
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.className="ShortField";
element2.type = "text";
element2.setAttribute("name","StartTime");
element2.setAttribute("readonly","true");
element2.value = StartTime.value;
cell2.appendChild(element2);
StartTime.value="";
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.className="ShortField";
element3.type = "text";
element3.setAttribute("name","EndTime");
element3.setAttribute("readonly","true");
element3.value = EndTime.value;
cell3.appendChild(element3);
EndTime.value="";
var cell4 = row.insertCell(3);
var element4 = document.createElement("input");
element4.className="ShortField";
element4.type = "text";
element4.setAttribute("name","MaterialID")
element4.setAttribute("readonly","true");
element4.value = MaterialID.value;
cell4.appendChild(element4);
MaterialID.value="";
var cell5 = row.insertCell(4);
var element5 = document.createElement("input");
element5.className="LongField";
element5.type = "text";
element5.setAttribute("name","Title");
element5.setAttribute("readonly","true");
element5.value = Title.value;
cell5.appendChild(element5);
Title.value="";
var cell6 = row.insertCell(5);
var element6 = document.createElement("input");
element6.className="ShortField";
element6.type = "text";
element6.setAttribute("name","row");
element6.setAttribute("readonly","true")
element6.style.display = "none";
element6.value = table.rows.length;
cell6.appendChild(element6);
}
function deleteRow(tableID) {
if (document.getElementById(tableID)) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
}
function updateRow(tableID) {
if (document.getElementById(tableID)) {
var StartTime = document.getElementById('txtStartTime');
var EndTime = document.getElementById('txtEndTime');
var MaterialID = document.getElementById('txtMaterialID');
var Title = document.getElementById('txtTitle');
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
//table.deleteRow(i);
chkbox.checked=false;
row.cells[1].childNodes[0].value=StartTime.value;
row.cells[2].childNodes[0].value=EndTime.value;
row.cells[3].childNodes[0].value=MaterialID.value;
row.cells[4].childNodes[0].value=Title.value;
}
}
StartTime.value="";
EndTime.value="";
MaterialID.value="";
Title.value="";
}catch(e) {
alert(e);
}
}
}
</SCRIPT>
This is working fine on my form but I am having trouble with the php processing script. I am having trouble with $query2. Please ignore the commented areas. They are for future headaches lol. Here is my processing script:
PHP:
?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
/*
$errors = array();
// Form Validation
$required_fields = array('List1', 'List2', 'Airdate', 'Description', 'Resolution');
foreach($required_fields as $fieldname) {
if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
$errors[] = $fieldname;
}
}
$fields_with_lengths = array('menu_name' => 30);
foreach($fields_with_lengths as $fieldname => $maxlength ) {
if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
}
if (!empty($errors)) {
redirect_to("errors.html");
}
*/
?>
<?php
$DiscrepType = mysql_prep($_POST['List1']);
$DiscrepDetail = mysql_prep($_POST['List2']);
$Airdate = $_POST['Airdate'];
$Description = mysql_prep($_POST['Description']);
$Resolution = mysql_prep($_POST['Resolution']);
$OnAirVariance = mysql_prep($_POST['OnAirVariance']);
$EquipID = mysql_prep($_POST['EquipID']);
$EquipLoc = mysql_prep($_POST['EquipLoc']);
$StartTime = array (mysql_prep($_POST['StartTime']));
$EndTime = array (mysql_prep($_POST['EndTime']));
$MaterialID = array (mysql_prep($_POST['MaterialID']));
$Title = array (mysql_prep($_POST['Title']));
$Row = array ($_POST['Row']);
/*
$INISatNSS806 = $_POST['INISatNSS806'];
$LaFamilia = $_POST['LaFamilia'];
$G15Analog = $_POST['G15Analog'];
$G15Digital = $_POST['G15Digital'];
$DirecTV = $_POST['DirecTV'];
$DISH = $_POST['DISH'];
$INSPhits = $_POST['INSPhits'];
$INSPolym = $_POST['INSPolym'];
$HalHDgal15 = $_POST['HalHDgal15'];
$HalGal15 = $_POST['HalGal15'];
$HalOlym = $_POST['HalOlym'];
$HalHits = $_POST['HalHits'];
*/
?>
<?php
$query1 = "INSERT INTO tblonairactivity (
DiscrepType, DiscrepDetail, Airdate, Description, Resolution, OnAirVariance, EquipID, EquipLoc
) VALUES (
'{$DiscrepType}', '{$DiscrepDetail}', '{$Airdate}', '{$Description}', '{$Resolution}', '{$OnAirVariance}', '{$EquipID}', '{$EquipLoc}'
)";
foreach($Row as $index) {
$query2 = "INSERT INTO tblAffectedProg (tblOnAirActivityID, StartTime, EndTime, MaterialID, Title
) VALUES (
LAST_INSERT_ID(), '{$StartTime}', '{$EndTime}', '{$MaterialID}', '{$Title}';
/*
$query3 = "INSERT INTO tblsatellites (
INISatNSS806, LaFamilia, G15Analog, G15Digital, DirecTV, DISH, INSPhits, INSPolym, HalHDgal15, HalGal15, HalOlym, HalHits
) VALUES (
{$INISatNSS806}, {$LaFamilia}, {$G15Analog}, {$G15Digital}, {$DirecTV}, {$DISH}, {$INSPhits}, {$INSPolym}, {$HalHDgal15}, {$HalGal15}, {$HalOlym}, {$HalHits}
)";
*/
$result = FALSE;
if (mysql_query('BEGIN')) {
if (mysql_query($query1) &&
mysql_query($query2))
$result = mysql_query('COMMIT'); // both queries looked OK, save
else
mysql_query('ROLLBACK'); // problems with queries, no changes.
}
if ($result) {
// Success!
redirect_to("success.html");
} else {
// Display error message.
echo "<p>Record creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php mysql_close($connection); ?>
Parse error: syntax error, unexpected T_STRING in C:\wamp\ on line 70
The strange thing is that line #70 is in one of the commented areas. How can this be? Can anyone please help me figure out what I am missing here?
Thanks,
Ken