...

View Full Version : Getting a parse error on what appears to be a valid statement



MrBiggZ
10-27-2009, 11:00 PM
Greetings!

I keep getting this error -> Parse error: parse error in C:\www\htdocs\ShiftRptForm\table-no-array.html on line 33

I really don't see what's wrong with it. Line 33 is -> if (count(errors$) >0) {

I'm trying to see if the count of the errors is > 0 then show the errors and re-display the form. So far no luck! :(

This is the script:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Empty Page</title>

<style type="text/css">
table {border-collapse:collapse;}
th.thShift {border-top:3px inset red;border-left:3px inset red;border-right:3px inset red;}
td.tdShift {border-bottom:3px inset red;border-left:3px inset red;border-right:3px inset red;text-align:center;}

th.jobStat1 {border-top:3px inset blue;border-left:3px inset blue;}
th.jobStat2 {border-top:3px inset blue;}
th.jobStat3 {border-top:3px inset blue;border-right:3px inset blue;}

td.jobStat1 {border-left:3px inset blue;}
td.jobStat3 {border-right:3px inset blue;}

td.LastjobStat1 {border-bottom:3px inset blue;border-left:3px inset blue;}
td.LastjobStat2 {border-bottom:3px inset blue;}
td.LastjobStat3 {border-bottom:3px inset blue;border-right:3px inset blue;}

tr.IC2-top {border-top:3px inset green;border-left:3px inset green;border-right:3px inset green;}
tr.IC2-sides {border-left:3px inset green;border-right:3px inset green;}
tr.IC2-bottom {border-bottom:3px inset green;border-left:3px inset green;border-right:3px inset green;}
</style>
</head>

<body>

<?php
if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
validate_form();
if (count(errors$) >0) {
show_form(errors$);
else
process_form();
}
else
show_form();
}


function show_form($errors = '') {
if ($errors) {
$error_text = '<tr><td>You need to correct the following errors:';
$error_text = '</td><td><ul><li>';
$error_text = implode('</li><li>',$errors);
$error_text = '</li></ul></td></tr>';
} else {
$error_text = '';
}

?>

<form method="POST" name="shiftreport" action="<?php print $_SERVER['PHP_SELF']; ?>">
<table name="shifttable">
<?php print $error_text ?>
<thead>
<tr>
<th class="thShift" colspan="5">Shift</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tdShift" colspan="5">1st <input type="radio" name="shift" value="1" onclick="setReadOnly(this)"/>&nbsp;&nbsp;&nbsp;2nd <input type="radio" name="shift" value="2" onclick="setReadOnly(this)"/>&nbsp;&nbsp;&nbsp;3rd <input type="radio" name="shift" value="3" onclick="setReadOnly(this)"/></td>
</tr>
</tbody>
<tr><td colspan="5"></td></tr>
<thead>
<tr>
<th class="jobStat1">Application</th>
<th class="jobStat2">Job Stream</th>
<th class="jobStat3">Status</th>
</tr>
</thead>

<tbody>
<tr>
<td class="jobStat1">ARTISAN</td>
<td><select style="width:390px;" name="artprogs">
<option value="no_job">------- select a job -------</option>
<option value="art_batch">ARTPROG/WFL/DAILY/BATCH</option>
<option value="art_image">ARTPROG/WFL/OPERATIONS/IMAGE</option>
<option value="art_wkly_batch">ARTPROG/WFL/WKLY/BATCH</option>
<option value="art_claims">ARTPROG/WFL/DAILY/CLAIMS</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="artprog_stat" OnChange="disableJobStream(this)">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
<td></td>
<td rowspan="11" vertical-align="baseline">
<table>
<thead>
<tr class="IC2-top" >
<th colspan="2">IC2 Output</th>
</tr>
</thead>
<thead>
<tr class="IC2-sides">
<th>Data</th>
<th>File Count</th>
</tr>
</thead>
<tbody>
<tr class="IC2-sides">
<td>Group Sponsor Mail</td>
<td><?php echo "<select name=\"Grp_Count\">";$i = 0;while ( $i <= 500 ) { echo "<option value=".$i.">".$i."</option>"; $i++; } echo "</select>"; ?></td>
</tr>
<tr class="IC2-sides">
<td>Insured Mail</td>
<td><?php echo "<select name=\"Ins_Count\">";$i = 0;while ( $i <= 500 ) { echo "<option value=".$i.">".$i."</option>"; $i++; } echo "</select>"; ?></td>
</tr>
<tr class="IC2-sides">
<td>Lienholder Mail</td>
<td><?php echo "<select name=\"Lnh_Count\">";$i = 0;while ( $i <= 500 ) { echo "<option value=".$i.">".$i."</option>"; $i++; } echo "</select>"; ?></td>
</tr>
<tr class="IC2-sides">
<td>State Mail</td>
<td><?php echo "<select name=\"Stm_Count\">";$i = 0;while ( $i <= 500 ) { echo "<option value=".$i.">".$i."</option>"; $i++; } echo "</select>"; ?></td>
</tr>
<tr class="IC2-sides IC2-bottom">
<td>Work Accident Insured Mail</td>
<td><?php echo "<select name=\"Wam_Count\">";$i = 0;while ( $i <= 500 ) { echo "<option value=".$i.">".$i."</option>"; $i++; } echo "</select>"; ?></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="jobStat1">SELF INSURED</td>
<td><select style="width:390px;" name="bllyprogs">
<option value="no_job">------- select a job -------</option>
<option value="blly_sischedpay">BLLYPROG/WFL/DAILY/SISCHEDPAY</option>
<option value="blly_dly_rpts">BLLYPROG/WFL/DAILY/REPORTS</option>
<option value="blly_wkly_gypsum">BLLYPROG/WFL/WKLY/REPORTS/GYPSUM</option>
<option value="blly_archivebkup">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
<option value="blly_close_audit">$UTIL/O/AUDIT/CLOSE/BLLY</option>
<option value="blly_datasiwh">DATASIWH/EXTRACTALL/DAILY/AUD/WFL</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="bllyprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">SBWC</td>
<td><select style="width:390px;" name="sbwcprogs">
<option value="no_job">------- select a job -------</option>
<option value="sbwc_warehouse">WORKPROG/WFL/DAILY/WAREHOUSE</option>
<option value="swbc_archivebkup">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
<option value="swbc_audit_close">$UTIL/O/AUDIT/CLOSE/WORKCOMP</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="sbwcprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">TCS</td>
<td><select style="width:390px;" name="tcsprogs">
<option value="no_job">------- select a job -------</option>
<option value="tcs_batch">TCS/WFL/DAILY/BATCH</option>
<option value="tcs_glchecks">BLPROG/WFL/COPY/REMOVE/GLCHECKS</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="tcsprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">IC</td>
<td><select style="width:390px;" name="icprogs">
<option value="no_job">------- select a job -------</option>
<option value="ic_indcont">BLPROG/WFL/DAILY/INDCONT</option>
<option value="ic_idcards">INDCON/WFL/PRINT/IDCARDS</option>
<option value="ic_ny_rpt">BLPROG/WFL/BATCH/NEWYORK/STATE-REPORT</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="icprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">TRUCKING</td>
<td><select style="width:390px;" name="truckprogs">
<option value="no_job">------- select a job -------</option>
<option value="trk_tkmarsh">TRUCKPROG/WFL/DAILY/TKINTMARSH</option>
<option value="trk_tkinternet">TRUCKPROG/WFL/DAILY/TKINTERNET</option>
<option value="trk_dly_batch">TRUCKPROG/WFL/DAILY/BATCH</option>
<option value="trk_tkschedpay">TRUCKPROG/WFL/DAILY/TKSCHEDPAY</option>
<option value="trk_dly_rpts">TRUCKPROG/WFL/DAILY/REPORTS</option>
<option value="trk_dly_claims">BLPROG/WFL/DAILY/CLAIMS</option>
<option value="trk_dly_audprem">TRUCKPROG/WFL/DAILY/AUDIT/PREMIUM</option>
<option value="trk_dly_balrpt">TRUCKPROG/WFL/DAILY/BALRPT</option>
<option value="trk_progmed">PROG-MEDICAL/WFL/DAILY/PMCLMEXT</option>
<option value="trk_agnucoprem">AGPROG/WFL/DAILY/AGNUCOPREM</option>
<option value="trk_wkly_fedex0005">BL/WFL/WKLY/FEDEX/0005</option>
<option value="trk_wkly_de542">TRUCKPROG/WFL/WKLY/DE542</option>
<option value="trk_wkly_fdxdisab">TRUCKPROG/WFL/WKLY/FDXDISAB</option>
<option value="trk_wkly_fdxdiserr">TRUCKPROG/WFL/WKLY/FDXDISERR</option>
<option value="trk_dumpdb">BL/WFL/ONLINE/DUMP/TRUCKING</option>
<option value="trk_datatkwh">DATATKWH/EXTRACTALL/DAILY/WFL</option>
<option value="trk_archivebkup">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="truckprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">SMALL FLEET</td>
<td><select style="width:390px;" name="smallprogs">
<option value="no_job">------- select a job -------</option>
<option value="smprg_dly_batch">SMALLPROG/WFL/DAILY/BATCH</option>
<option value="smprg_dly_cert">SMALLPROG/WFL/DAILY/CERTS</option>
<option value="smprg_opr_prt">SMALLPROG/WFL/OPERATIONS/PRINT</option>
<option value="smprg_wkly_batch">SMALLPROG/WFL/WKLY/BATCH</option>
<option value="smprg_dly_dhwhclaims">SFCLAIMS/WFL/DAILY/DWHCLAIMS</option>
<option value="smprg_dly_rpts">SFCLAIMS/WFL/DAILY/REPORTS</option>
<option value="smprg_wkly_rpts">SFCLAIMS/WFL/WEEKLY/REPORTS</option>
<option value="smprg_dumpdb">BL/WFL/ONLINE/DUMP/SFDB/1WORKER</option>
<option value="smprg_audit_close">$UTIL/O/AUDIT/CLOSE/SFDB</option>
<option value="smprg_datasfwh">DATASFWH/EXTRACTALL/DAILY/WFL</option>
<option value="smprg_archivebkup">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="smallprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">PERSONAL AUTO</td>
<td><select style="width:390px;" name="persauto">
<option value="no_job">------- select a job -------</option>
<option value="pauto_dly_batch">PERSAUTO/WFL/DAILY/BATCH</option>
<option value="pauto_opr_image">PERSAUTO/WFL/OPERATIONS/IMAGE</option>
<option value="pauto_opr_print">PERSAUTO/WFL/OPERATIONS/PRINT</option>
<option value="pauto_wkly_batch">PERSAUTO/WFL/WKLY/BATCH</option>
<option value="pauto_dly_claims">PERSAUTO/WFL/DAILY/CLAIMS</option>
<option value="pauto_dumpdb">BL/WFL/ONLINE/DUMP/DB1/1WORKER/FULL</option>
<option value="pauto_close_audit">$UTIL/O/AUDIT/CLOSE/DB1</option>
<option value="pauto_datawh">DATAWH/EXTRACTALL/DAILY/WFL</option>
<option value="pauto_dumpwh">BL/WFL/OFFLINE/DUMP/WAREHOUSE</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="persauto_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">ISO</td>
<td><select style="width:390px;" name="isoprog">
<option value="no_job">------- select a job -------</option>
<option value="iso_batch">ISOPROG/WFL/BATCH/ISOSAGDAILY</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="isoprog_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1">BACKUPS LIVE</td>
<td><select style="width:390px;" name="bkuplive">
<option value="no_job">------- select a job -------</option>
<option value="bl_dumpdb">BL/WFL/ONLINE/DUMP/BLDB</option>
<option value="bl_archivebkup">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
<option value="bl_close_audit">$UTIL/O/AUDIT/CLOSE/BLDB</option>
<option value="bl_datardwh">DATARDWH/EXTRACTALL/DAILY/REIN/WFL</option>
<option value="bl_archivebkup1">(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
<option value="bl_fiche">BL/WFL/FICHE/DISK</option>
</select>
</td>
<td class="jobStat3"><select style="width:100px;" name="bkuplive_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
<tr>
<td class="jobStat1 LastjobStat1">TEST SITE INSTRUCTIONS</td>
<td class="LastjobStat2"><select style="width:390px;" name="testsite">
<option value="no_job">------- select a job -------</option>
<option value="test_dbdisable">WFL/TESTLYON/DATABASE/ONLINE/DISABLE</option>
<option value="test_bdfiles">UTIL/WFL/REMOVE/TESTLYON/BDFILES</option>
<option value="test_archivebkup">BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP</option>
</select>
</td>
<td class="jobStat3 LastjobStat3"><select style="width:100px;" name="testsite_stat">
<option value="none">None</option>
<option value="stopped">Stopped</option>
<option value="running">Running</option>
<option value="completed">Completed</option>
</select>
</td>
</tr>
</tbody>

</table>
<input type="hidden" name="stage" value="process">
<input type="submit" value="Submit">
</form>
<?php
}

function validate_form () {
$errors = array();
if (isset($_POST['shift']) == false)
$errors[] = "NO shift selected";
if (($_POST['artprogs'] == 'no_job') && ($_POST['artprog_stat'] != 'completed'))
$errors[] = "ARTPROG status not equal to completed and NO job selected";
if (($_POST['artprogs'] != 'no_job') && ( ($_POST['artprog_stat'] == 'stopped') ||
($_POST['artprog_stat'] == 'running')))
{ print 'oh noooooooooooooos';
$errors[] = "ARTPROG status cannot be STOPPED or RUNNING with no job selected!!";
}
return $errors;
}

function process_form() {
print "Shift: " . $_POST['shift'] . "<br/>\n";
print "Artprog: " . $_POST['artprogs'] . "<br/>\n";
print "Artprog Status: " . $_POST['artprog_stat'] . "<br/>\n";
}
?>
</body>
</html>

Thanks for the help!

FWDrew
10-27-2009, 11:02 PM
$errors

Not


errors$

djm0219
10-27-2009, 11:36 PM
Your braces for the if/else are also not balanced.



if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
validate_form();
if (count($errors) >0) {
show_form($errors);
}
else {
process_form();
}
} else {
show_form();
}

MrBiggZ
10-28-2009, 03:39 PM
Doh! I got bit! .. TWICE! Sorry! Man do I feel stupid!

Question I have now is this. Once I display my errors the form elements all reset. Which I don't want, since you'd want to correct the mistakes and re-submit. Hitting back give me the form with the form elements with the values submitted, understandably. Do I have to tell the form what the values of all the fields are after I display the errors??

Please ignore all my displaying my feeble way of debugging. I'm kicking butt right now but not really sure how to get the form to re-display with the old values. :confused:

I have to attach the php script since I've exceeded the amount of characters allowed in a message. :( Change the file extension from .txt to .html

Thanks!

Fumigator
10-28-2009, 04:30 PM
Question I have now is this. Do I have to tell the form what the values of all the fields are after I display the errors??


Yeah, that's pretty much what you've got to do. It's a real pain, especially with selectboxes. Here's an example that uses the ternary condition syntax:



<select style="width:390px;" name="artprogs">
<option value="no_job"<?php echo ($_POST['artprogs'] == "no_job" ? " selected='selected'" : "");?>>------- select a job -------</option>
<option value="art_batch"<?php echo ($_POST['artprogs'] == "art_batch" ? " selected='selected'" : "");?>>ARTPROG/WFL/DAILY/BATCH</option>
<option value="art_image"<?php echo ($_POST['artprogs'] == "art_image" ? " selected='selected'" : "");?>>ARTPROG/WFL/OPERATIONS/IMAGE</option>
<option value="art_wkly_batch"<?php echo ($_POST['artprogs'] == "art_wkly_batch" ? " selected='selected'" : "");?>>ARTPROG/WFL/WKLY/BATCH</option>
<option value="art_claims"<?php echo ($_POST['artprogs'] == "art_claims" ? " selected='selected'" : "");?>>ARTPROG/WFL/DAILY/CLAIMS</option>
</select>


http://us3.php.net/ternary

There are ways to make this process a little easier. One way is to assign all of the values that make up your selectbox to an array. I like to use the "value" of each option as the keys of the array and each option's text as the values of the array. For example:



$artProgsArray = Array(
"no_job" => "------- select a job -------",
"art_batch" => "ARTPROG/WFL/DAILY/BATCH",
"art_image" => "ARTPROG/WFL/OPERATIONS/IMAGE",
"art_wkly_batch" => "ARTPROG/WFL/WKLY/BATCH",
"art_claims" => "ARTPROG/WFL/DAILY/CLAIMS");

echo '<select style="width:390px;" name="artprogs">';
foreach ($artProgsArray as $key => $val) {
echo "<option value='$key'".($_POST['artprogs'] == $key ? "selected='selected'" : "").">$val</option>\n";
}
echo "</select>";


You can see that using this method is it's pretty easy to adjust the values and texts of each option just by manipulating the array. It takes the replication out of the code. And, it's not that much of a stretch to see how you can change things to store this array in a file or database table, which could then put the form's values in the hands of a website administrator via an admin-type page.

MrBiggZ
10-29-2009, 01:23 AM
Thank you sir! I did the later of the two and that worked nicely!

I started plugging away at doing radio buttons in a similar fashion but I don't see were my syntax is getting messed up. I could be blind too!

I get a parse error on line 7.



<?php
$shiftValues = array( '1','2','3' );
$shiftPrompt = array( '1st','2nd','3rd' );

for($Index=0;$Index<count($shiftPrompt);$Index++)
{
echo $shiftPrompt[$Index] . " <input type='radio' name='shift' value='" . $shiftValues[$Index] . "'" . ($shiftPrompt[$Index] == '0') ? "' Checked>";
}
?>


Meh! I gave in too soon! I fixed it! YEAH!!!!!
I guess you could call that an inline expression .. never done those before! :thumbsup:



<?php
$shiftValues = array( '1','2','3' );
$shiftPrompt = array( '1st','2nd','3rd' );
$current = '0';
for($Index=0;$Index<count($shiftPrompt);$Index++)
{
echo $shiftPrompt[$Index] . " <input type='radio' name='shift' value='" . $shiftValues[$Index] . "'" . ($shiftPrompt[$Index] == $current ? "checked='Checked'" : "").">";
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum